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 ask user input of a string, then ask user input of...
Write a Python program to ask user input of a string, then ask user input of what letters they want to remove from the string. User can either put in "odd", "even" or a number "n" that is greater than 2. When user input "odd", it will remove the characters which have odd numbers in the sequence of the string. When user input "even", it will remove the characters which have even numbers in the sequence of the string. When...
(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 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...
By using Python code answer the following parts: A) Write a program to ask the user...
By using Python code answer the following parts: A) Write a program to ask the user to input their name and then output the type and length of the input. B) Write a program to output the last 11 letters of 'Introduction to Indiana'. C) Write a program to output the 3rd to the 11th letters of 'Introduction to Indiana'. D) Write a program to ask the user to input a float number and output the rounded value of it...
Python programming Write a program that prompts the user to input the three coefficients a, b,...
Python programming Write a program that prompts the user to input the three coefficients a, b, and c of a quadratic equationax2+bx+c= 0.The program should display the solutions of this equation, in the following manner: 1. If the equation has one solution, display ONE SOLUTION:, followed by the solution, displayed with4 digits printed out after the decimal place. 2. If the equation has two real solutions, display TWO REAL SOLUTIONS:, followed by the two solutions, each displayed with4 digits printed...
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()*...
In Python: Problem 4. Write a program [call it minmax.py] that accepts three integers in the...
In Python: Problem 4. Write a program [call it minmax.py] that accepts three integers in the range [0-100] as input from the user. Your program should then determine and print the smallest and largest integers in the values entered by the user using comparison operators *not* using predefined min or max Python functions. For instance: If the user input is: 36 5 99 your program should give as output: min = 5 max = 99 If the user input is:...
Python Programming Build a python programming that asks the user for a three-letter substring. The program...
Python Programming Build a python programming that asks the user for a three-letter substring. The program should then proceed to read the file strings.txt. Each line in strings.txt will contain a string. Your program should then test to see how many non-overlapping occurrences of the three-letter substring occur in that string and test whether the string is a palindrome. The program should then proceed to create an output file string_stats.txt, which contains the original data on one line and the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT