r/pythonhelp • • May 15 '22

HOMEWORK String not existing and added loop when not mean to be there

This code is meant to count the amount of Vowels and Consonants is a string and when I run it I get an error that string does not exist (I am not allowed to change the names of the functions) also when I did the get string part it looped twice for some reason and I do not know why, here is code:

def Main():
    Get_String_from_User()
    Count_Vowels(string)
    Count_Consonants(string)
    print(f'The string you entered includes {Count_Vowels} vowels and {Count_Consonants} consonants.')
def Get_String_from_User():
    string=input("Enter a string: ")
    return string
def Count_Vowels(string):
    vowels=0
    Vowels=set("aeiouAEIOU")
    for Letters in string:
        if Letters in Vowels and Letters.isalpha:
            vowels+=1
    return vowels
def Count_Consonants(string):
    consonants=0
    Vowels=set("aeiouAEIOU")
    for Letters in string:
        if Letters not in Vowels and Letters.isalpha:
            consonants+=1
Main()
2 Upvotes

1 comment sorted by

1

u/htepO May 15 '22

Get_String_from_User() returns a string and Count_Vowels() will return an integer once you fix isalpha(), but those returned values are not stored anywhere. Count_Consonants() doesn't even return anything.

I'd recommend revisiting the section in your course that deals with the basics of variables and functions.