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 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))

0 0
Add a comment Improve this question Transcribed image text
Answer #1
# get user input
user_string = input("Enter a sentence: ")

# create and initialize variables
upper_case, lower_case, digits, spaces, punctuations = 0, 0, 0, 0, 0

# loop conditions and increment
for ch in user_string:
    if ch.islower():
        lower_case += 1
    elif ch.isupper():
        upper_case += 1
    elif ch.isdigit():
        digits += 1
    elif ch.isspace():
        spaces += 1
    else:
        punctuations += 1

# print totals
print("Uppercase: " + str(upper_case))
print("Lowercase: " + str(lower_case))
print("Digits: " + str(digits))
print("Spaces: " + str(spaces))
print("Punctuations: " + str(punctuations))
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
  • 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.

  • Write a C program that prompts the user for an input string with all lowercase letters....

    Write a C program that prompts the user for an input string with all lowercase letters. Your program should then sort the characters in the string and print the sorted string. Assume that the string contains no spaces and has at most 30 lowercase characters. Your program should loop continually until the user enters “q” to quit.

  • C programming (not c++) This programs input is a series of words. All words consist of...

    C programming (not c++) This programs input is a series of words. All words consist of only lowercase letters(a-z), no uppercase letters or digits or punctuation or other special symbols. The program reads until end-of-file, and then prints out the lowercase letters that were not seen in the input. Enter your input: the quick brown fox jumps over the lazy old dog Missing letters: enter your input: roll tide missing letters: a b c f g h j k m...

  • Exercise #3: write a Java program that prompts the user to enter a sentence. The program...

    Exercise #3: write a Java program that prompts the user to enter a sentence. The program has to find the print: a. the position of vowels in the sentence. b. the number of vowels in the sentence (A, a, U, u, E, e, O, o, I, i) c. the number of characters as numbers or special characters (other than English letters a.z, A..Z). Hint: remember to ignore the spaces. Sample input-output: Enter the sentnse: UAEU is the university of the...

  • I'm having trouble getting my program to output this statement Enter a sentence: Test! There are...

    I'm having trouble getting my program to output this statement Enter a sentence: Test! There are 5 total characters. There are 1 vowel. There are 1 UPPERCASE letters. There are 3 lowercase letters. There are 1 other characters. Here's my code: #include<string.h> #include<stdio.h> #include<stdbool.h> int main() { char str[100]; int i; int vowels=0; int UC; int LC; int Others; int c; printf("Enter a sentence: \n"); gets(s); LC=countLC(&s); UC=countUC(&s); Others=countOthers(&s); printf("There are %d total characters.\n", ; for(i=0; i<strlen(str); i++){ if(isVowel(str[i])) vowels++;...

  • Can you all fix this coding below, if so "ASAP" would be great? Write a program...

    Can you all fix this coding below, if so "ASAP" would be great? Write a program that prompts the user to input a string and outputs the string in uppercase letters using dynamic arrays. int main() {​ char *str; ​ ​ int strLen;​ int len;​ char ch;​ ​ int i;​ ​ cout << "Enter the size of the string: ";​ cin >> strLen;​ cout << endl;​ ​ cin.get(ch);​ ​ str = new char[strLen + 1];​ ​ cout << "Enter a...

  • I was asked to write a program that when divisible by 2- reverses the order of...

    I was asked to write a program that when divisible by 2- reverses the order of the letters in a sentence when divisible by 3- changes all lowercase letter into uppercase letters in a sentence when divisible by 5 skips the vowels in a sentence this is what I have so far. my reverseMode works fine. #include <iostream> #include <string> #include<cstring> using namespace std; void reverseMode(char* str); void upperMode(char* str); void goodbyeVowels(char* str); char str[50], rstr[50]; //initializing my character arrray...

  • C++ program by netBeans java language Exercise #2: Write a java program that prompts the user...

    C++ program by netBeans java language Exercise #2: Write a java program that prompts the user to enter a sentence. The program has to find the print: a. the position of vowels in the sentence. b. the number of vowels in the sentence (A, a, U, u, E, e, 0, o, I, i) c. the number of characters as numbers or special characters (other than English letters a..z, A..Z). Hint: remember to ignore the spaces. Sample input-output: Enter the sentnse:...

  • Write a PYTHON program that allows the user to navigate the lines of text in a...

    Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

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