Question

Char type: Edit the provided starter-code char_type.py so it takes the user to enter some text,...

Char type: Edit the provided starter-code char_type.py so it takes the user to enter some text, then display the number of vowels, consonants,digits, and special characters in the text. In english the vowels are the letters "a" , "e" , "i", "o", "u", "y". All other letters are consonants. The digits are "0"-"9". The special characters are those that are not letters or digits. The program should countthe number of each type of character in the text user enters, then print the result like this:

vowels:14

consonants:8

Digits:9

Special:3

hint : use if-elif -else statements to distinguish the different types of characters.

Python3 code

0 0
Add a comment Improve this question Transcribed image text
Answer #1
# char_type.py
vowels = 0
consonants = 0
digits = 0
specials = 3

punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'

# Reading text
text = input("Enter text: ")

# Looping through each characters of text
for x in text.lower():
    if(x.isalpha()):
        if(x in "aeiou"):
            vowels += 1
        else:
            consonants += 1
    elif(x.isdigit()):
        digits += 1
    elif(x in punctuation):
        specials += 1
# Printing output
print("vowels:"+str(vowels)+"\nconsonants:"+str(consonants)+"\nDigits:"+str(digits)+"\nSpecial:"+str(specials))

Output:

15 sentence Enter text: this is my vowels:5 consonants:11 Digits:5 Special:3 Process finished with exit code 0

Add a comment
Know the answer?
Add Answer to:
Char type: Edit the provided starter-code char_type.py so it takes the user to enter some text,...
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
  • a. Ask the user for the input of a letter (char type). Write a function that...

    a. Ask the user for the input of a letter (char type). Write a function that takes a char as the argument (parameter) and returns the ASCII value of that char back to the caller. Call the function using the char variable and taking input from the user (no validation required). Display the value in ASCII. b. Write a program that takes a char as the argument (parameter) and uses a loop to interrogate the char, calling a function that...

  • This is Python The program should accept input from the user as either 7-digit phone number...

    This is Python The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12. The program should not crash if the user enters invalid...

  • 14.3: More Sentences Write a program that allows a user to enter a sentence and then...

    14.3: More Sentences Write a program that allows a user to enter a sentence and then the position of two characters in the sentence. The program should then report whether the two characters are identical or different. When the two characters are identical, the program should display the message: <char> and <char> are identical! Note that <char> should be replaced with the characters from the String. See example output below for more information. When the two characters are different, the...

  • (1) Prompt the user to enter a string of their choosing. Store the text in a...

    (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue! You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews...

  • I need eclipse code for : Write a program that analyzes text written in the console...

    I need eclipse code for : Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowercase letters should be counted together (for example, both ‘A’ and ‘a’ should count as an A). Any characters that are not letters should be ignored. You must prompt the user to enter the text to be analyzed. Then, for any letter that appeared at least once...

  • The skeleton code (starter file) for the problem is pasted below: def phoneNumber(letters): result = ""...

    The skeleton code (starter file) for the problem is pasted below: def phoneNumber(letters): result = "" # ADD YOUR CODE HERE return result def loadEvents(filename): events = {} # ADD YOUR CODE HERE return events def timeline(events): # ADD YOUR CODE HERE return # DO NOT modify or remove the code below! We will use it for testing. if __name__ == "__main__": # Problem 1: Decoding Telephone Numbers ph = input("Enter the text to translate: ") print("The corresponding phone number...

  • Need this in C The starter code is long, if you know how to do it...

    Need this in C The starter code is long, if you know how to do it in other way please do. Do the best you can please. Here's the starter code: // ----------------------------------------------------------------------- // monsterdb.c // ----------------------------------------------------------------------- #include #include #include // ----------------------------------------------------------------------- // Some defines #define NAME_MAX 64 #define BUFFER_MAX 256 // ----------------------------------------------------------------------- // Structs typedef struct { char name[NAME_MAX]; int hp; int attackPower; int armor; } Character; typedef struct { int size; Character *list; } CharacterContainer; // ----------------------------------------------------------------------- //...

  • please answer correctly and follow the code structure given [JavaFX/ Exception handing and text I/O] 1....

    please answer correctly and follow the code structure given [JavaFX/ Exception handing and text I/O] 1. Write a program for the following. NOTE that some of these steps are not dependent on each other. Using methods is mandatory. Make sure to use methods where it makes sense. a. Ask the user for a series of integers entered from the keyboard. Use a sentinel value such as 999 to end the input process. If the entered values are not integers, throw...

  • In c++ Write a program that allows the user to type in any one-line question and then answers tha...

    in c++ Write a program that allows the user to type in any one-line question and then answers that question. Your program won't really respond to the question, rather it will read a random response from a file. Requirements Your program should have a function called getQuestion() which prompts the user for a question and returns the number of characters in the question (including spaces and punctuation, not including the ending newline). If the user enters an empty string they...

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
ADVERTISEMENT