Question: Write a program that prompts for a sentence and calculates the number of uppercase letters, lowercase letters, digits, and punctuation. Output the results neatly formatted

Write a program that prompts for a sentence and calculates the number of uppercase letters, lowercase letters, digits, and punctuation. Output the results neatly formatted and labeled in columns.

how I can make this program in a more simple way.

# get user input user_string = input("Enter a sentence: ") # create and initialize variables upper_case = 0 lower_case = 0 digits = 0 spaces = 0 punctuations = 0 x = len(user_string) #loop conditions and increment for i in range(0, x, 1): if(ord(user_string[1]) >= 97) and (ord(user_string[1]) <= 122): lower_case += 1 elif(ord(user_string[1]) >= 65) and (ord(user_string[1]) <= 90): upper_case += 1 elif(ord(user_string[1]) >= 48) and (ord(user_string[1]) <= 57): digits += 1 elif(ord(user_string[1]) == 32): spaces += 1 else: punctuations += 1 # print totals print(" Uppercase: " + str(upper_case)) print(" Lowercase: " + str(lower_case)) print(" Digits: " + str(digits)) print("Punctuations: " + str(punctuations))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!