Question

write a program that prompts for a sentence and calculates the number of uppercase letters, lowercase...

write a program that prompts for a sentence and calculates the number of uppercase letters, lowercase letters, digits and punctuations. output the results neatly formatted and labeled in columns.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import string
def string_test(s):
    d={"UPPER_CASE":0, "LOWER_CASE":0,"digit":0,"punctuation":0}
    for c in s:
        if c.isupper():
           d["UPPER_CASE"]+=1
        elif c.islower():
           d["LOWER_CASE"]+=1
        elif c.isdigit():
            d["digit"]+=1
        else:
            for i in c:
               if i in string.punctuation:
                   d["punctuation"]+=1
        
    print ("Original String : ", s)
    print ("No. of Upper case characters : ", d["UPPER_CASE"])
    print ("No. of Lower case Characters : ", d["LOWER_CASE"])
    print ("No. of digit: ", d["digit"])
    print ("No. of punctutation : ", d["punctuation"])
s=input("Enter a sentence:")
string_test(s)

OUTPUT:-

Enter a sentence:I am Supriyo,My age is 23.
Original String :  I am Supriyo,My age is 23.
No. of Upper case characters :  3
No. of Lower case Characters :  14
No. of digit:  2
No. of punctutation :  2
Add a comment
Know the answer?
Add Answer to:
write a program that prompts for a sentence and calculates the number of uppercase letters, lowercase...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT