Why does it print multiple times

Hello mates, wanted to ask why do you think this prints my string and counts the vowels multiple times. Help would be greatly appreciated. Language is Python.

def vowel_count(str):
count = 0
vowel = set(“aeiou”)

for vowels in str:
if vowels in vowel:
count = count + 1
print(“The amount of vowels is :”, count)

str = “Jose can do it if he tries.”
vowel_count(str)

Can’t know for sure because the code provided lacks indentation. May probably something related to that too. I copy/pasted your code and corrected the indentation. It works correctly.

def vowel_count(str):
    count = 0
    vowel = set(“aeiou”)
    
    for vowels in str:
        if vowels in vowel:
            count = count + 1
    print("The amount of vowels is :", count)

str = "Jose can do it if he tries."
vowel_count(str)

The amount of vowels is : 9

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.