Question

Write a program in python to display all the consonant in the user input. E.g. user...

Write a program in python to display all the consonant in the user input.

E.g. user input: Hello Good Day to you.

Output:

consonant H = 1

consonant l = 2

consonant G = 1  

consonant d = 1

consonant D = 1

etc

Homework Answers

Answer #1

PYTHON PROGRAM ===>

from collections import OrderedDict
def remove_duplicate(str1):
return "".join(OrderedDict.fromkeys(str1))

sentence = input("Enter : ")
newsentence = remove_duplicate(sentence) # create new string from sentence after remove duplicate character
for ch in newsentence:
if(ch=='B' or ch=='b' or ch=='C' or ch =='c' or ch=='D' or ch=='d' or ch=='F' or ch=='f' or ch=='G' or ch=='g' or ch=='H' or ch=='h' or ch== 'J' or ch=='j' or ch=='K' or ch =='k' or ch=='L' or ch=='l' or ch=='M' or ch=='m' or ch=='n' or ch=='N' or ch=="P" or ch=="p" or ch=='Q' or ch=='q' or ch=='R' or ch =='r' or ch=='S' or ch=='s' or ch=='T' or ch=='t' or ch=='V' or ch=='v' or ch=="W" or ch=="w" or ch=='X' or ch=='x' or ch=='Y' or ch =='y' or ch=='Z' or ch=='z'):
count =0
for x in sentence :
if(ch==x):
count= count+1
print("consonent ",ch," = ",count)
  

CODE SCREENSHOT ====>

OUTPUT SCREENSHOT ===>

UPDATED CODE ===>


sentence = input("Enter : ")
newsentence = "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz" # a string contains all consonant in uppercase and lowercase
for ch in newsentence:
if(ch=='B' or ch=='b' or ch=='C' or ch =='c' or ch=='D' or ch=='d' or ch=='F' or ch=='f' or ch=='G' or ch=='g' or ch=='H' or ch=='h' or ch== 'J' or ch=='j' or ch=='K' or ch =='k' or ch=='L' or ch=='l' or ch=='M' or ch=='m' or ch=='n' or ch=='N' or ch=="P" or ch=="p" or ch=='Q' or ch=='q' or ch=='R' or ch =='r' or ch=='S' or ch=='s' or ch=='T' or ch=='t' or ch=='V' or ch=='v' or ch=="W" or ch=="w" or ch=='X' or ch=='x' or ch=='Y' or ch =='y' or ch=='Z' or ch=='z'):
count =0
for x in sentence :
if(ch==x):
count= count+1
print("consonant ",ch," = ",count)
  

OUTPUT ===>

Know the answer?
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
Similar Questions
Write a Python program to calculate the area of a circle. The user needs to input...
Write a Python program to calculate the area of a circle. The user needs to input the value of the radius of the circle. area = 3.14 x radius x radius You should use a function named circlearea to perform the calculation 3. Write a Python program to calculate the area of a square. The user needs to input the value of the length of the square. area = len*len You should use a function named squarearea to perform the...
(8 marks) Write a program to ask user to input an integer and display the special...
Write a program to ask user to input an integer and display the special pattern accordingly. REQUIREMENTS The user input is always correct (input verification is not required). Your code must use loop statements (for, while or do-while). Your program should use only the following 3 output statements, one of EACH of the followings: System.out.print("-"); // print # System.out.print("+"); // print + System.out.println(); // print a newline Your code must work exactly like the following example (the text in bold...
Write a java program that repeatedly prompts the user to input a string starting with letters...
Write a java program that repeatedly prompts the user to input a string starting with letters from the English alphabet. The program must stop getting input when the user inputs the string “STOOOOP”. Then the program must display the words starting with each letter from the alphabet in a separate line (e.g. you need to make a new line after all words starting with a specific letter are finished.
(Python Programming) Write a program that prompts a user for a positive integer and then uses...
(Python Programming) Write a program that prompts a user for a positive integer and then uses a loop to calculate and display the sum of specific fractions as follows: Let's say the user enters 5, then your program will compute: 1/5 + 2/4 + 3/3 + 4/2 + 5/1 which is 8.7.
Use Python: # Problem Set 03: - Write a program to input an uncertain string *S*...
Use Python: # Problem Set 03: - Write a program to input an uncertain string *S* of words and space/tab - Remove space/tab in S - Remove identical words - Sort all words in the order of a-z - Print the output strings - Example: - Input String: "hello world and practice makes perfect and hello world again" - Output String: "again and hello makes perfect practice world" - Tips: - use *set* to remove identical words, - use *sorted()*...
Write a python program that calculates the area of triangle. The user will be asked to...
Write a python program that calculates the area of triangle. The user will be asked to enter the base (b) and the height (h). The formula to calculate the area is: Triangle_area=(bh)/2 Note: the program should print the area to the user: (for example: the area of the triangle is: 34.3)
IN PYTHON : Write a program that asks the user for a number. Write the number...
IN PYTHON : Write a program that asks the user for a number. Write the number to a file called total.txt. Then ask the user for a second number. Write the new number on line 2 with the total for both numbers next to it separated by a comma. Then ask the user for a third number and do the same. Keep asking for numbers until the person puts in a zero to terminate the program. Close the file. Be...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
using python Write a program that displays all of states in the U.S. and display each...
using python Write a program that displays all of states in the U.S. and display each state that begins with the letter A.
Write a Python program that plays a number guessing game with a human user. The human...
Write a Python program that plays a number guessing game with a human user. The human user will think of a number between 1 and 100, inclusive. Then the program has to guess what the user entered. keep track of the number of interaction it takes for the computer to guess the number. sample run: enter number to be guessed:88 output: you entered 88, and it took the program 3 iterations to guess.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT