mardi 28 août 2018

Calling a function within an elif statement [duplicate]

This question already has an answer here:

I know it's not the best way to write code, but I would like to fix what I have- not necessarily change the entire thing. I know there are parts where the code will stop since I haven't created anything else for it. At this point what I would like to fix is that once I call the initial_username function, and I enter N as the input for the confirm variable, it still prints what is under the if statement rather than calling the function within the elif statement.

def wrong_data():
    print("I'm sorry, I didn't get that.")
    fix_name()

def fix_name():
    print("Let's try that again.")
    fn_error= input('Please re-enter your first name: ')
    ln_error= input('Please re-enter your last name: ')
    second_confirm= input('Is your full name ' + str(fn_error) + ' ' + str(ln_error) + '? Please enter Y or N: ')
    if second_confirm== 'Y' or 'y':
        print('Thank you, ' + str(fn_error) + ' ' + str(ln_error) + '.')

def initial_username():
user_fn= input('Please enter your first name: ')
user_ln= input('Please enter your last name: ')
confirm= input('Is your full name ' + str(user_fn) + ' ' + str(user_ln) + '? Please enter Y or N: ')
if confirm == 'Y'or 'y':
    print('Thank you, ' + str(user_fn) + ' ' + str(user_ln) + '.')
elif confirm == 'N' or 'n':
    fix_name()
else:
    wrong_data()

initial_username()

Aucun commentaire:

Enregistrer un commentaire