Log in and password

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • A~dam
    New Member
    • Jan 2008
    • 1

    Log in and password

    I am trying to grasp the basics of "IF" statements in the python.
    But for what ever reason cant.

    Code:
    username= raw_input('Username for this program : ')
    
    if username < 23:
            username = 23
            print 'I am sorry you are not the user of this program.'
    elif username == 23:
            print "Welcome user #23"
    elif username != 23:
            exit
    else:
            exit
    Now whats that's suppose to do is ask for user name much like it dose, and if it is equal to the user name of twenty three then precede to asking for the password. (in this case the pasword uses the same if statement), although if you get the user name wrong then if will not let you go any further and will exit the program, as seen in the lines were else: exit.
    although when i run the application, if i get the username wrong it moves on to the password ands that even if i hit enter for both will allow me to enter the program....

    I need it so that if you get the user name wrong you will be exitied out of the program and if you get the password wrong, same deal...or....

    heres the or.

    If you get the user name wrong to GOTO what ever line the program starts on...
    but that GOTO can only be applied to the user name.
  • KaezarRex
    New Member
    • Sep 2007
    • 52

    #2
    Originally posted by A~dam
    I am trying to grasp the basics of "IF" statements in the python.
    But for what ever reason cant.

    Code:
    username= raw_input('Username for this program : ')
    
    if username < 23:
            username = 23
            print 'I am sorry you are not the user of this program.'
    elif username == 23:
            print "Welcome user #23"
    elif username != 23:
            exit
    else:
            exit
    Now whats that's suppose to do is ask for user name much like it dose, and if it is equal to the user name of twenty three then precede to asking for the password. (in this case the pasword uses the same if statement), although if you get the user name wrong then if will not let you go any further and will exit the program, as seen in the lines were else: exit.
    although when i run the application, if i get the username wrong it moves on to the password ands that even if i hit enter for both will allow me to enter the program....

    I need it so that if you get the user name wrong you will be exitied out of the program and if you get the password wrong, same deal...or....

    heres the or.

    If you get the user name wrong to GOTO what ever line the program starts on...
    but that GOTO can only be applied to the user name.
    The main problem I notice with your code is that you are trying to compare a string and an integer in your IF statements. The "raw_input" function returns a string, so you must either compare strings or cast the "username" as in integer.

    This might point you in the right direction:
    [CODE=python]
    import sys

    username= raw_input('User name for this program : ')

    if username == '23':
    print "Welcome user #23"
    else:
    print 'I am sorry you are not the user of this program.'
    sys.exit()

    password = raw_input('Pass word : ')

    if password == 'rosebud':
    print "User authenticated"
    else:
    print 'Incorrect password'
    sys.exit()[/CODE]

    Comment

    • Patrick C
      New Member
      • Apr 2007
      • 54

      #3
      Or, if i'm not mistaken, you could just take the string you get from raw_imput and turn that into an integer.

      (this code has not be tested and i am a rookie, so there could be an error)...

      username_string = raw_input("Ente r your usernamer: ")

      unsername_integ er = int(username_st ring)

      this way you can computer numbers to numbers rather than text to numbers.

      Comment

      Working...