Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
This program should say a vowel only for the letters a, e, i, o and u. But for the letter k it also says a vowel.
Explain in one or two sentences why, and write two correct versions.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. Split the condition into the pieces that or joins.
The pieces are letter == "a", then "e", "i", "o" and "u". Only the first piece is a comparison. The other four are bare pieces of text, and text that is not empty counts as True. One True piece is enough for or, so the whole condition is True for every letter.
Two correct versions.
Version 1: letter == "a" or letter == "e" or letter == "i" or letter == "o" or letter == "u"
Version 2: letter in "aeiou"
Put either one after the word if and a colon.
Check. For k, "k" in "aeiou" is False, so the program says not a vowel.
Answer: The pieces after the first or are not comparisons, and non-empty text is always True. Write each comparison in full, or use in.
Log in to join the discussion.
Loading…