Another make task, and this time the program has to look at every character of a word, one at a time.
A primary school teacher wants a simple program to help pupils find out how many vowels there are in different words. The vowels are A, E, I, O and U. Y does not count.
Write a program that:
"A", "E", "I", "O" or
"U",The loop runs over the positions in the word, range(len(word)), and the slice
word[i:i+1] is the character at position i. To check whether that
character is a vowel you can compare it with each of the five vowels in turn,
or put the five vowels in a list and use in, as you did with lists.
Converting the word first is what lets the program count a and A alike: a
comparison with "A" only matches a capital letter.
The tests also check your code: a program that does not use a for loop,
slicing and upper() does not pass.
The question first, worded exactly like this:
Enter a word:
Then one line, where COUNT is the number of vowels in the word:
Number of vowels: COUNT
Input:
banana
Output:
Enter a word:
Number of vowels: 3
Input:
Aeroplane
Output:
Enter a word:
Number of vowels: 5
A word with no vowels at all is still answered, with a count of 0: Rhythm
gives Number of vowels: 0.
Ask the question with its own print, and read the answer with a bare
input() on the next line, rather than passing the question to input(...).
The question is part of the output that is checked here, so its spelling,
capital letters and punctuation count.
Make sure that you check for the following things:
upper() is stored, as in word = word.upper(). On its own,
word.upper() changes nothing.if, which is inside the
loop.print of the count is not indented, so it runs once, after the
loop.str() before it is joined onto the text.range(len(word)), not
range(len(word) - 1).