The function given below is written to accept a string s as a parameter and return the number of vowels appearing in the string. The code has certain errors. Observe the code carefully and rewrite it after removing all the logical and syntax errors. Underline all the corrections made.
def CountVowels(s):
c=0
for ch in range(s):
if 'aeiouAEIOU' in ch:
c=+1
return(ch)range(s) needs a number, and s is a string. for ch in range(s): to for ch in s:. Now ch holds one letter per pass. c=+1 the + is just a plus sign on the number 1. So c is set to 1 again and again. Use c+=1 to add 1 each time. def CountVowels(s):
c=0
for ch in s:
if ch in 'aeiouAEIOU':
c+=1
return(c)
Test: CountVowels('Education') now returns 5.