我想要统计字符串中特定字符的出现次数,但结果不正确。
这是我的代码:
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
声明在哪里?你是如何生成输出的?输入是什么? - Thomas Upton'aabccc'.count('c')
- dawgy
。 - beruic