Computer Science, asked by saadbukharicis, 1 day ago

python program to count consonant letters gets from user input

Answers

Answered by Equestriadash
2

Co‎de:

\tt s\ =\ in put("Enter\ a\ string:\ ")\\cs\ =\ 0\\for\ i\ in\ s:\\{\ \ \ \ \ }if\ i\ not\ in\ ("AEIOUaeiou"):\\{\ \ \ \ \ }{\ \ \ \ \ }cs\ =\ cs\ +\ 1\\print("'"\ +\ s\ +\ "'",\ "has",\ cs,\ "consonants.")

Explanation:

We retrieve the input from the user, by using the \tt in put() function that is designed for the same and assign it to a variable s. We then create another variable cs, that is going to store the count of the consonants. A for loop, which is an iteration statement used for repeated checking, is then initialized. The traversing variable i goes through each character in the string and checks if the characters aren't present in the set of vowels, using a membership operator that is used to check if a subset is part of a set or not. If a character isn't present in the set of vowels, cs increments by 1. Once the loop ends, the final value is printed.

Similar questions