-4

Assume s is a string of lower case characters.

Write a program that counts up the number of vowels contained in the string s. Valid vowels are: 'a', 'e', 'i', 'o', and 'u'. For example, if s = 'azcbobobegghakl', your program should print:

Number of vowels: 5

I came up with this code but I might be missing out on something I can't quite figure out yet

s = 'fddjhkloeavhkiyaeio'
vowels = ['a','e','i','o','u']
count = 0

for i in s:
    if i in vowels:
        count = count + 1
    print("Number of vowels: " , str(count))

this is the error Number of vowels: 8

* ERROR: Expected 6, got 8. *

elixenide
  • 44,308
  • 16
  • 74
  • 100
Makena
  • 1
  • 1

1 Answers1

1

You have a issue first pointed out by @castis above. Your print statement is in the wrong place. If you put it inside the for loop, it means that it will print every time the for loop iterates, so bring it back 2 indents. Like so:

s = 'fddjhkloeavhkiyaeio'
vowels = ['a','e','i','o','u']
count = 0

for i in s:
    if i in vowels:
        count = count + 1

print("Number of vowels: " , str(count))