Я пытаюсь подсчитать, сколько вхождений содержит определенные символы в строке, но результат неправильный.Count Vowels in String Python
Вот мой код:
inputString = str(input("Please type a sentence: "))
a = "a"
A = "A"
e = "e"
E = "E"
i = "i"
I = "I"
o = "o"
O = "O"
u = "u"
U = "U"
acount = 0
ecount = 0
icount = 0
ocount = 0
ucount = 0
if A or a in stri :
acount = acount + 1
if E or e in stri :
ecount = ecount + 1
if I or i in stri :
icount = icount + 1
if o or O in stri :
ocount = ocount + 1
if u or U in stri :
ucount = ucount + 1
print(acount, ecount, icount, ocount, ucount)
Если я вхожу письмо A
результат будет: 1 1 1 1 1
Где 'stri' объявлен? Как вы создаете выход? Какой вклад? –
Для подсчета символов строка использует метод count: ''aabccc'.count (' c ')' – dawg
Возможный дубликат [Подсчитайте количество гласных в предложении и покажите наиболее частое] (http: // stackoverflow. com/questions/19933875/count-the-of-of-of-vowels-in-a-предложение-и-display-the-most-often) – inspectorG4dget