Answer to Question #163670 in Python for Ray

Question #163670

Write a program with a function that accepts a string as an argument and returns the number of vowels that the string contains. The application should have another function that accepts a string as an argument and returns the number of consonants that the string contains.

The application should let the user enter a string and should display the number of vowels and the number of consonants it contains.

Sample output:

Enter a string: california

The string you entered includes 5 vowels and 5 consonants



1
Expert's answer
2021-02-15T14:09:15-0500
#Function to count consonents

def Consonents(s):

  Count=0

  vowels = ["A","E","I","O","U","a","e","i","o","u"]

  for r in range(0,len(s)):

    for c in range(0,len(s[r])):

      if s[r][c] in vowels:

        Count=Count+1

  return(len(s)-Count)

   

#Function to count vowels

def VowelCounts(s):

  Count=0

  vowels = ["A","E","I","O","U","a","e","i","o","u"]

  for r in range(0,len(s)):

    for c in range(0,len(s[r])):

      if s[r][c] in vowels:

        Count=Count+1

  return(Count)




InputStr = input("Enter a string: ")

print("The string you entered contains %d vowels and %d consonents"%(VowelCounts(InputStr),Consonents(InputStr)))


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS