Why don't receive the right answer ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

24th Dec 2017, 10:46 PM
NIMA
NIMA - avatar
9 Answers
+ 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.
25th Dec 2017, 1:39 AM
Ben Smylie (he/him)
Ben Smylie (he/him) - avatar
+ 4
That's weird; it works perfectly fine for me: https://code.sololearn.com/cQkZH7zq28fD/? ref=app
24th Dec 2017, 10:57 PM
blackcat1111
blackcat1111 - avatar
+ 4
If you tell me the exact error at the exact line it occurs, I could try to fix it for you. 😉
24th Dec 2017, 11:08 PM
blackcat1111
blackcat1111 - avatar
+ 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. 😉
25th Dec 2017, 12:07 AM
blackcat1111
blackcat1111 - avatar
+ 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. 😉
25th Dec 2017, 1:57 AM
blackcat1111
blackcat1111 - avatar
+ 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. 😉
24th Dec 2017, 10:50 PM
blackcat1111
blackcat1111 - avatar
+ 2
24th Dec 2017, 11:17 PM
NIMA
NIMA - avatar
+ 1
in Solo Learn IDE i receive 3 from your string but in Spyder IDE on my PC not ! anyway thanks a lot
24th Dec 2017, 11:07 PM
NIMA
NIMA - avatar
0
in my code for "i am nima" i receive 9 that is wrong quantity but in your code edit, i receive SyntaxERROR
24th Dec 2017, 10:54 PM
NIMA
NIMA - avatar