Ich habe eine Zuweisung über Strings in Schleife und ich muss herausfinden, wie viele (a, e, ich, o, u) in der Eingabe. Ich habe es getan, aber ich denke, es ist zu lang. Ich möchte es kürzer machen, aber ich habe keine Ahnung wie.Wie kann ich es kürzer und besser machen?
Dies ist mein Code:
x=input("enter the taxt that you need me to count how many (a,e,i,o,u) in it:")
a=len(x)
x1=0
x2=0
x3=0
x4=0
x5=0
for i in range(a):
h=ord(x[i])
if h == 105:
x1+=1
elif h == 111:
x2+=1
elif h == 97:
x3+=1
elif h == 117:
x4+=1
elif h == 101:
x5+=1
print("There were",x3,"'a's")
print("There were",x5,"'e's")
print("There were",x1,"'i's")
print("There were",x2,"'o's")
print("There were",x4,"'u's")
Sollen wir _guess_, dass dies ... Python? – deceze
Ja, es ist Python, sorry hat nicht erwähnt, dass – abdulraman
Mögliche Duplikate von [Wie Vokale und Konsonanten in Python zählen?] (Http://stackoverflow.com/questions/43164161/how-to-count-vowels-and-consonants -in-Python) – BWMustang13