Python generating username and password program

I am just a beginner programmer 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 enter the correct password as shown, it always says the password is wrong.

+3


source to share


2 answers


You need to assign the second userInput input statement:



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.")

      

+8


source


You forget to assign 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.")

      

+2


source







All Articles