0

What's wrong with this code I wrote?

a=input() g=['a','e','i','o','u'] for i in g: p=a.find(i) if p==-1: print("this word has no vowels") else: print("this words has vowels") I was funding if the words has any vowel or not

26th May 2024, 5:42 AM
Raine04
Raine04 - avatar
5 Answers
+ 5
Your code prints "this word has no vowel" or "this words has vowels" for each character in the input string. To avoid this:- https://sololearn.com/compiler-playground/cldgwUNWAK0h/?ref=app
26th May 2024, 7:06 AM
Gulshan Mahawar
Gulshan Mahawar - avatar
+ 4
# Hi, Raine04 ! # Here's another one with time complexity O(1), which is very low. # Convert all characters to lower case. input_string = input("Enter a word: ").lower() print(repr(input_string), '\n') vowels = "aeiou" # Use intersections of sets to check if vowels are present in the input_string. if set(input_string) & set(vowels): print("-> This word has vowels") else: print("-> This word has no vowels") # Here's a more compact version: https://sololearn.com/compiler-playground/cBiuCubi8ozP/?ref=app
26th May 2024, 9:37 AM
Per Bratthammar
Per Bratthammar - avatar
+ 1
Thank-you both
26th May 2024, 4:10 PM
Raine04
Raine04 - avatar
+ 1
I think p=-1 means the vowel of i variable is not in a Exemple a="jujistsu kaysen" p=a.find("o")=-1 o not in a
27th May 2024, 5:03 PM
Dimitri Bien-aimé
Dimitri Bien-aimé - avatar
0
Goood
27th May 2024, 9:30 AM
Bello Rukayat
Bello Rukayat - avatar