Python program to count the number of words, digits, uppercase letters, and lowercase letters
Problem Definition:
Develop a Python program that accepts a sentence and find the number of words, digits, uppercase letters, and lowercase letters.
Video Tutorial
Source Code to Python program to count the number of words, digits, uppercase letters, and lowercase letters
s = input("Enter a sentence: ") w, d, u, l = 0, 0, 0, 0 l_w = s.split() w = len(l_w) for c in s: if c.isdigit(): d = d + 1 elif c.isupper(): u = u + 1 elif c.islower(): l = l + 1 print ("No of Words: ", w) print ("No of Digits: ", d) print ("No of Uppercase letters: ", u) print ("No of Lowercase letters: ", l)
Output
Case 1:
Enter a sentence: Mahesh Huddar 591236
No of Words: 3
No of Digits: 6
No of Uppercase letters: 2
No of Lowercase letters: 10
Case 2:
Enter a sentence: Mahesh Huddar Do like share and Subscribe
No of Words: 7
No of Digits: 0
No of Uppercase letters: 4
No of Lowercase letters: 31
Summary:
This tutorial discusses how to write a Python program to find the number of words, digits, uppercase letters, and lowercase letters. If you like the tutorial share it with your friends. Like the Facebook page for regular updates and the YouTube channel for video tutorials.