dimanche 4 février 2018

Defining a Function in python 3.6 and expecting True or False but returning None

def gender():

Creating a function that should return True or False

    gener = input('Choose \"1\" for Male or \"2\" for Female: ') 

"gener" should receive "1" or "2" as string

    if gener == '1':
        print('You selected Male')
        return True
    elif gener == '2':
        print('You selected Female')
        return False
    else:

Here happens the problem. It should execute again the function gender() so the user could reinsert "1" or "2" correctly

        print('Invalid character')
        gender()

But when printing the function gender() it returns "None" even if gender() is executed again in order to receive a new value, continuing with the value of Else statement

print(gender())

Aucun commentaire:

Enregistrer un commentaire