Python creating username and password program

53,162

Solution 1

You need to assign the second input statement to userInput:

if userInput == username:
    userInput = input("Password?\n")   
    if userInput == password:
       print("Welcome!")
    else:
       print("That is the wrong password.")
else:
    print("That is the wrong username.")

Solution 2

You forget asign the variable:

if userInput == username
   userinput = input("Password?\n")   
    if userInput == password:
        print("Welcome!")
    else:
        print("That is the wrong password.")
else:
    print("That is the wrong username.")
Share:
53,162

Related videos on Youtube

Polly the Programmer
Author by

Polly the Programmer

Updated on July 17, 2022

Comments

  • Polly the Programmer
    Polly the Programmer almost 2 years

    I am just a beginner programmer as of right now, and I am trying to create a username/password program. Here is my code below:

    username = 'Polly1220'
    
    password = 'Bob'
    
    userInput = input("What is your username?\n")
    
    if userInput == username:
        a=input("Password?\n")   
        if a == password:
            print("Welcome!")
        else:
            print("That is the wrong password.")
    else:
        print("That is the wrong username.")
    

    Whenever I run my program and input the correct password as shown, it always says that the password is incorrect.

    • Eugene Sh.
      Eugene Sh. almost 7 years
      You never assign the password input to anything
  • Ajax1234
    Ajax1234 almost 7 years
    I did. Fixed now.
  • Polly the Programmer
    Polly the Programmer almost 7 years
    Thank you so much!
  • Ajax1234
    Ajax1234 almost 7 years
    Glad I could help. Please consider accepting this response as answered so other users know it has an answer. Thank you.
  • Damian Lattenero
    Damian Lattenero almost 7 years
    You were really fast on this one! plus one for that pal :)

Related