‹ PrevQuestion 3 / 3 · latest first
✓ Board-verified
Computer Science · 2026 · 2 marks
CBSE 2026 · Central · Set 4 · Q26
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…
The function given below is written to accept a string $\displaystyle \mathbf{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)Marking-scheme solution
def CountVowels(s):
c=0
for ch in s: #Correction-1
if ch in 'aeiouAEIOU': #Correction-2
c+=1 #OR c=c+1 #Correction-3
return(c) #Correction-4OR
def CountVowels(s):
c=0
for ch in range(len(s)): #Correction-1
if s[ch] in 'aeiouAEIOU': #Correction-2
c=c+1 #Correction-3
return c #Correction-4More from Functions
CBSE Class 12 Computer Science past-paper question from the 2026 board exam, with the answer as CBSE’s own marking scheme gives it. Where our answers come from.