+ 1
Trying to work out the Vowel challenge in Python 3
I am trying to figure out how to print the number of each vowel either using a list(which did not work for me) or creating a count for each vowel (not exactly DRY, I know) So far this is the most updated version of my code and is throwing back indentation errors towards the print statement, showing a as a non existant variable: inp = input("Input: ") acount = 0 ecount = 0 icount = 0 ocount = 0 ucount = 0 if "a" in inp: a = acount + 1 if "e" in inp: e = ecount + 1 if "i" in inp: i = icount + 1 if "o" in inp: o = ocount + 1 if "u" in inp: u = ucount + 1 print("A: " + a + "\nE:" + e +"\nI: " + i + "\nO: " + o + "\nU: " + u)
1 Odpowiedź
+ 1
i = input("Input: ")
print(i + "\n")
i = i.lower()
c = [0, 0, 0, 0, 0]
v = "aeiou"
for l in i:
if "a" == l:
c[0] += 1
if "e" == l:
c[1] += 1
if "i" in l:
c[2] += 1
if "o" == l:
c[3] += 1
if "u" == l:
c[4] += 1
print("A = ", c[0], "\nE = ", c[1], "\nI = ", c[2], "\nO = ", c[3], "\nU = ", c[4])
I managed to get the program to work, but am still interested if I could only use the variables v and c instead of individually listing letters. Thank you for the help