+ 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

19th Nov 2022, 10:33 AM
isaiah
isaiah - avatar
9 odpowiedzi
+ 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".
19th Nov 2022, 12:16 PM
Lothar
Lothar - avatar
+ 5
Scott D , it is mentioned that the task is from *python datastructures*. (exercise is 3.2) this is a part of the task description: You need to make a program that counts the number of vowels in a given text. The vowels are a, e, i, o, and u. ... so it is correct to search for 'aeiou' only
20th Nov 2022, 1:05 PM
Lothar
Lothar - avatar
+ 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
19th Nov 2022, 11:05 AM
Jayakrishna 🇮🇳
+ 4
Scott D , what vowels are missing?
20th Nov 2022, 12:11 PM
Lothar
Lothar - avatar
+ 2
This code in principle can not print nine values, watch the indentation in your code.
19th Nov 2022, 10:39 AM
Solo
Solo - avatar
+ 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
19th Nov 2022, 11:05 AM
Giannis
Giannis - avatar
+ 1
Is this for Code Coach? If so it may not pass - you are missing some vowels.
20th Nov 2022, 11:53 AM
Scott D
Scott D - avatar
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.
20th Nov 2022, 12:42 PM
Scott D
Scott D - avatar
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.
20th Nov 2022, 1:58 PM
Scott D
Scott D - avatar