+ 1
Vowels in words
Words = input() Count = 0 For i in words: If i == “a” or i == “e” or i == “i” or I== “o” or i == “u”: Count += 1 Print (count) #output needs to be 9 But the results is 1,2,3,4,5,6,7,8,9 Please can any help me to to input the right code to get a ouput as 9
9 ответов
+ 7
isaiah ,
as already mentioned: correct the indentation.
furthermore:
> for, if, print has to be spelled in lower case
> all vowel characters in the if statement are surrounded with incorrect quotes. use: 'a' or "a".
+ 4
If the print statement is inside loop then it prints 9 times. If the print statement is after loop, it prints only once..
see in this, about indentation.
look at code sample
https://www.sololearn.com/discuss/2534829/?ref=app
https://www.sololearn.com/discuss/2204604/?ref=app
+ 4
Scott D ,
what vowels are missing?
+ 2
This code in principle can not print nine values, watch the indentation in your code.
+ 1
it looks like you have the print function inside the loop, maybe has a space before the print. In python need to be careful with spaces and tabs in your code
+ 1
Is this for Code Coach? If so it may not pass - you are missing some vowels.
0
I'm not familiar with python, it may be more forgiving, but in c++ a!=A.
So Out!=out. The posters code would fail in c++ as five vowels are missing.
Edit: I just looked and yes, python is case sensitive.
0
I do not beleive that to be true. This is the task for c++:
Task:
Write a program that takes in a string as input, counts and outputs the number of vowels (A, E, I, O, U).
Input Format:
A string (letters can be both uppercase or lower case).
And yet the hidden tests fail if you do not compare for both upper and lower case. Does the task specially say only lower case is to be checked? Probably not.
Even so, it is good coding practice to expect either upper or lower case in such comparisons.
So we'll have to agree to disagree.