on-internet
← Community

How do I iterate and count vowels in a string?

Stack Overflow ·

I am trying to count the vowels in a string ("hello world" should result in 3) and print the count. It gives: TypeError: 'int' object is not iterable on the for loop. How do I check each character and print count? How do I fix my for loop and if logic, what should the loop iterate over, why isn't checking vowels == ["a"] working, and where do I place print()? vowels = ["a" , "e" , "i" , "o" , "u"] count = 0 for vowels in count: if vowels == ["a"]: count += 1 elif vowels == ["e"]: count += 1 elif vowels == ["i"]: count += 1 elif vowels == ["o"]: count += 1 elif vowels == ["u"]: print(vowels)

Comments

Sign in or sign up to comment and upvote.

No comments yet.