+ 2
How to find vowel in string
word1=input("1st word:") word2=input("2nd word:") count=0 if len(word1) > len(word2): for i in word1: if i in (A,a,I,i,E,e,O,o,U,u): count +=1 else: for i in word2: if i in (A,a,I,i,E,e,O,o,U,u): count +=1 print(count) this is my code. but I am getting an error
6 odpowiedzi
+ 3
text=input()
n=[]
vow='AaEeIiOoUu'
for o in vow:
l=text.count(o)
n.append(l)
print(sum(n))
+ 8
The letters in the if-statement s need to be a string, for example "A"
+ 7
word1=input("1st word:")
word2=input("2nd word:")
count=0
if len(word1) > len(word2):
for i in word1:
if i in ('A','a','I','i','E','e','O','o','U','u'):
count +=1
else:
for i in word2:
if i in ('A','a','I','i','E','e','O','o','U','u'):
count +=1
print(count)
+ 3
below is an example of combining some of the solutions brought up by Imadez , Lisa , and Jay Matthews .
i created a variable that holds the string of vowels and in the if statement i transform each letter to be in lowercase.
# How to find vowel in string
word1=input("1st word:")
word2=input("2nd word:")
# create tuple with vowels
vowels = ("aeiou")
count=0
# count vowels if lowercase letter is in vowels tuple
if len(word1) > len(word2):
for i in word1:
if i.lower() in vowels:
count +=1
else:
for i in word2:
if i.lower() in vowels:
count +=1
print(count)
+ 2
There are 2 possibles:
1 Look for capitals.
2 Look for small.
If (1) : convert the string to uppercase
If (2) : convert the string to lowercase
Either case make a tuple of characters :
And...
Search for the appropriate character and increment a count variable every time ⏲️.
+ 1
Gouri Shinde How about this one? :-
print(sum(1 for x in input().lower() if x in "aeiou"))
# Hope this helps