+ 1

Python code help

What I want to do is once the password and username has been entered correctly, it will print hey (just for testing, I want it to move on to another piece of code) But if the user and password are incorrect or any incorrect combination, it will keep asking until you input the correct combination (it would be even better if you had a certain amount of attempts) I've written this but i'm not great a progamming, so naturally, its doesn't work I've written a code like this that does work however it doesnt keep asking until I get it right. Thanks :) User =("Plurgie") Pass =("password123") correct = False while correct == False: Tryuser = input("Enter Username: ") Trypass = input("Enter Password: ") if Tryuser == User and Trypass == Pass: correct == True if correct == True: print("Hey")

18th Nov 2018, 4:24 PM
Plurgie
Plurgie - avatar
8 Respostas
+ 4
Also you should change in the if statement --> correct = True . ( you want to change the value of correct from false to true. When you use == it just compares it.)
18th Nov 2018, 5:11 PM
Proff
Proff - avatar
+ 1
Like this: User = "Plurgie" # you don't need parenthesis here Pass = "password123" correct = False while not correct: Tryuser = input("Enter Username: ") Trypass = input("Enter Password: ") if Tryuser == User and Trypass == Pass: correct = True print("Hey")
18th Nov 2018, 4:58 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
thanks everyone :)
18th Nov 2018, 6:40 PM
Plurgie
Plurgie - avatar
0
There is no need to use the for loop inside the first while loop. Use the if statement inside the first while loop. You don't need a second while loop, just put the print outside the first while loop. P.S. The code will not work very well in the code Playground because, in the code Playground you need to enter all input at the start of the program.
18th Nov 2018, 4:40 PM
Ulisses Cruz
Ulisses Cruz - avatar
0
Ulisses Cruz Ive changed it, it still doesnt work?
18th Nov 2018, 4:51 PM
Plurgie
Plurgie - avatar
0
Are you getting an indentation error?
18th Nov 2018, 4:52 PM
Ulisses Cruz
Ulisses Cruz - avatar
0
Ulisses Cruz No, it just keeps asking for input
18th Nov 2018, 4:54 PM
Plurgie
Plurgie - avatar
0
Did you put the if inside the while loop?
18th Nov 2018, 4:54 PM
Ulisses Cruz
Ulisses Cruz - avatar