0

I'm having trouble with what I think MAY be a bug, or something that I'm missing.

This is the code:

#----------------------
import time
from time import sleep
#----------------------




class main():
     def menu():
        choice = input('Do you wish to register, or login?: ')
        if choice == 'register' or 'Register' or 'REGISTER':
            pass
        if choice == 'login' or 'Login' or 'LOGIN':
            main.login()



    def login():
        usr = 'SYSTEM'
        pas = 'DEFAULT'
        usr1 = input('Please type in your username credentials: ')
        pas1 = input('Now please type in your password: ')
        if usr != usr1 or pas != pas1:
            print('Your username and/or password is incorrect.Please try again.')
            time.sleep(3)
            main.login()
        if usr == usr1 and pas == pas1:
            print('Success!')




  def register():
    print('This feature is currently un-available. A defualt System password has been generated.\n Username: SYSTEM \n Password: DEFAULT \n')
    time.sleep(3)
    print('You will now be redirected to the login menu.\n')
    time.sleep(3)
    main.login()


main.menu()

If you run this code, you will see that if you attempt to login straight away, it will ALWAYS return the register function.
Is this a bug, or am I being stupid?
Thanks, Ciaran

  • Note, this isn't an exact duplicate -- but only because you didn't realize where your problem was. And by the way -- You're not being stupid. I've seen this question LOTS of times on StackOverflow. The problem is that python is _so_ expressive that occasionally we think it should be even more expressive than it actually is. – mgilson Jul 11 '14 at 20:41
  • Im still quite not sure where im going wrong? – user3821313 Jul 11 '14 at 20:44
  • Compare your if statements in menu to those in login. – AMacK Jul 11 '14 at 20:52
  • `choice == 'login' or 'Login' or 'LOGIN'` evaluates as `(choice == 'login') or 'Login'` -- (the last `'LOGIN'` is completely irrelevant). Since `'Login'` is a non-empty string, it always evaluates to `True` in a boolean context. – mgilson Jul 11 '14 at 20:52
  • You need `if choice == 'register' or choice == 'Register' or choice == 'REGISTER':` but better version is `if choice.lower() == 'register':`. – furas Jul 11 '14 at 20:54
  • Thanks for all the comments guys, really appreciate it! – user3821313 Jul 11 '14 at 21:15

0 Answers0