+ 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

29th Jul 2021, 8:21 PM
Gouri Shinde
Gouri Shinde - avatar
6 Answers
+ 3
text=input() n=[] vow='AaEeIiOoUu' for o in vow: l=text.count(o) n.append(l) print(sum(n))
31st Jul 2021, 7:44 PM
Monjurul Hasan Nabil
Monjurul Hasan Nabil - avatar
+ 8
The letters in the if-statement s need to be a string, for example "A"
29th Jul 2021, 8:25 PM
Lisa
Lisa - avatar
+ 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)
29th Jul 2021, 8:26 PM
Imadez
Imadez - avatar
+ 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)
30th Jul 2021, 1:29 AM
you are smart. you are brave.
you are smart. you are brave. - avatar
+ 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 ⏲️.
30th Jul 2021, 4:09 PM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
Gouri Shinde How about this one? :- print(sum(1 for x in input().lower() if x in "aeiou")) # Hope this helps
31st Jul 2021, 2:44 PM
Calvin Thomas
Calvin Thomas - avatar