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
5 ответов
+ 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
+ 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
+ 1
Thank-you both
+ 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
0
Goood