samedi 11 juillet 2020

Python Error Variable referenced before assigned [duplicate]

player_gender = str(input("Are you male or female? "))
loop_end == 3 

def family_name():
    while loop_end == 3:          #ELSE STATEMENT DOES NOT WORK 
        if player_gender == str("Male") or player_gender == str("male"): 
            print('')
            global wife_name
            wife_name = str(input("What is your wifes name? "))
            print('')
            global son_name
            son_name = str(input("Whats your sons name? "))
            print('')
            global daughter_name
            daughter_name = str(input("Whats your daughters name? "))
            break
        elif player_gender == str("Female") or player_gender == str("female"): 
            print('')
            global husband_name 
            husband_name = str(input("What is your husbands name? "))
            print('')
            son_name = str(input("Whats your sons name? "))
            print('')
            daughter_name = str(input("Whats your daughters name? "))
            break
        else: 
            print('')
            print("That is not a valid input, input male for male or female or female")
            print('')
            player_gender = str(input("Are you male or female? "))
            continue
    
family_name()

This is giving me an error on the variable player_gender saying that it is referenced before assigned, however I have clearly assigned it before the function? I am trying to make a text based game, and the user has to input their gender to be able to change details about their family, however this is not working, as I have already shown. Can anyone please help? Thank you!

This is the exact error that is given

Aucun commentaire:

Enregistrer un commentaire