0

I am making an ATM system and it doesn't seem to be working properly, as no matter what is inputted, Python3 keeps on thinking that the first option ('n' or 'N') is correct. Can anyone help me solve this problem please?

Thank You :)

def show_menu():
proceed = False
while proceed == False:
    print('Card Inserted?')
    inp_card = input('Y / N > ')

    if inp_card == 'n' or 'N':
        print('Please input your card')
    elif inp_card == 'y' or 'Y':
        proceed = True
        print('Please input your PIN')
        inp_pin = input('PIN > ')
    else:
        print('Invalid Option!')
else:
    pass
NSantu10
  • 11
  • 1

1 Answers1

2

when you do if a or b python understands it as: "if a is true or if b is true".

so python will think if inp_card == 'n' or 'N': means "if inp_card == 'n' is true or if 'N' is true"

'N' in python is considered to be true (here's a link explaining what things are true and false in python)

what you need to do instead is:

    if inp_card == 'n' or inp_card == 'N':
        print('Please input your card')
    elif inp_card == 'y' or inp_card == 'Y':
        proceed = True
        print('Please input your PIN')
        inp_pin = input('PIN > ')
  • 1
    An alternative would be `if inp_card in {'n', 'N'}` or to use `inp_card = input('Y / N > ').lower()` and to just check for the lower character afterwards. – Matthias Aug 12 '23 at 11:27