A while loop in my code is not looping.
I've tried ensuring the while loop would loop but no loop was executed.
#Name_Input
login = 1
while login == 1:
print("Enter the username and password \n")
username = input("Username: ")
password = input("Password: ")
if password and username != "cameron" and "123":
print("\nWrong username or password... \nTry Again...")
login = 1
I am expecting the loop to go back to the login when the login details are entered incorrectly.
2 Answers 2
login = 1
while login == 1:
print("Enter the username and password \n")
username = str(input("Username: "))
password = str(input("Password: "))
if username == "cameron" and password == "123":
login=2
else:
print("\nWrong username or password... \nTry Again...")
Sign up to request clarification or add additional context in comments.
Comments
Try this if syntax:
login = 1
while login == 1:
print("Enter the username and password \n")
username = input("Username: ")
password = input("Password: ")
if password != "123" or username != "cameron":
print("\nWrong username or password... \nTry Again...")
login = 1
else:
login = -1
answered Sep 30, 2019 at 10:36
Paolo Mossini
1,0522 gold badges16 silver badges25 bronze badges
1 Comment
Some programmer dude
The condition still won't work as the OP expects (I believe). Please read up on De Morgan's laws. And read the message being printed, it contains the right logic. :)
lang-py
ifdoesn't work as you expect. You need to do something likeif condition_1 or condition_21is a boolean value. Actually all objects in Python have a boolean value, thebooltype was a later (and highly debated FWIW) addition.