0

I have defined a vowel count() function which is to count the number of vowels in a user input returning count from the vowel count() function. My def structure doesn't work.

Addition: How not equal the user input into any number?

# Defining Function
def vowelCount(data):  # Counting the number of vowels in a word
    count = 0
    list1 = ["a", "e", "i", "o", "u"]
    for input in data:
        if input in list1:
            count += 1
    return count
while redo == True:
  try:
    userinput = str(input("Enter String Data: "))
    if (userinput >= 0) or (userinput <= 0):  # userinput should not be equal to a number
        print("2Please enter an alphabetical value.")
        break
    except:
        print("!Please enter an alphabetical value.")
        exit()
    print("Number of Vowels: ", vowelCount(userinput))
Utpal Kumar
  • 300
  • 2
  • 13
Gamma
  • 3
  • 4
  • There are a few bugs in your code. To start, the `return` has the wrong indentation. – Mark Ransom May 16 '21 at 03:15
  • Your `return` statement is inside the loop, so you return after checking the first character. It should be indented one level less. – kaya3 May 16 '21 at 03:15
  • Does this answer your question? [How do I merge a list of dicts into a single dict?](https://stackoverflow.com/questions/3494906/how-do-i-merge-a-list-of-dicts-into-a-single-dict) – programandoconro May 16 '21 at 03:15

1 Answers1

0

I think it's the problem of your indenting. return should be the same indent as for. As for the number checking, you can simply use userinput.isalpha(). This checks if every element in the string is in the alphabet.

oplxy
  • 129
  • 1
  • 1