0
Why don't receive the right answer ?
I want to calculate the quantity of vowel characters among mentioned vowel list in codes, but it doesn't calculate right quantuty ... why ? https://code.sololearn.com/cD7zXBDTODt5/?ref=app
9 Respostas
+ 2
Hi, I've made a few changes here. As others have said, be careful with cases.
And try to remember that Python is your friend :) there's often a simpler way to do the work of a long repetitive line like a character check. Nice code! Hope this helps
def vowel_letters(string):
string_normalized = str(string).lower()
# As you've changed the input string to lowercase,
# you should therefore check against lowercase vowels
i = 0
for char in string_normalized:
# the 'in' operator is handy here:
if char in 'aeiou':
i += 1
return i
print(vowel_letters('A short sentence about lasagne'))
# this code seems to work on all python3 versions I've tried.
+ 4
That's weird; it works perfectly fine for me:
https://code.sololearn.com/cQkZH7zq28fD/?
ref=app
+ 4
If you tell me the exact error at the exact line it occurs, I could try to fix it for you. 😉
+ 3
You should change the line to small letters;
if char == "a" or char == "e" or char == "i" or char == "o" or char == "u":
#Et cetera
Python is case sensitive. 😉
+ 3
@Benjamin Smylie Hmm, I've never thought of the in keyword. Nice idea! I don't code in Python much nowadays, but I must admit that it is shorter and more efficient. 😉
+ 2
It should be:
if char == "a" or char == "e" or char == "i" or char == "o" or char == "u":
Because otherwise it'll check if char == "a" OR "e". As "e" is a non-null value, "e" will return True. Similarly for "i", "o", "u".
Also, you changed the entire string to lowercase, so the string will contain no uppercase letters. If you want to type the above in uppercase, you should change the entire string to uppercase.
Hope this helped. 😉
+ 2
I receive 0 in Spyder IDE !!
Screenshot:
https://www.dropbox.com/s/9iz6daq14asp5w8/20171225_024159.jpg?dl=0
+ 1
in Solo Learn IDE i receive 3 from your string
but in Spyder IDE on my PC not !
anyway thanks a lot
0
in my code for "i am nima" i receive 9 that is wrong quantity but in your code edit, i receive SyntaxERROR