All MicroEvals
HumanEval Question 64
Create MicroEval
Header image for HumanEval Question 64

HumanEval Question 64

HumanEval Question 64

Prompt

Complete the following Python function: ```python FIX = """ Add more test cases. """ def vowels_count(s): """Write a function vowels_count which takes a string representing a word as input and returns the number of vowels in the string. Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a vowel, but only when it is at the end of the given word. Example: >>> vowels_count("abcde") 2 >>> vowels_count("ACEDY") 3 """ ```

Answer guidance

Canonical solution (function body): vowels = "aeiouAEIOU" n_vowels = sum(c in vowels for c in s) if s[-1] == 'y' or s[-1] == 'Y': n_vowels += 1 return n_vowels

Drag to resize
Drag to resize
Drag to resize
Drag to resize
Drag to resize