+ 1

repeating input in python

how can i make the code repeats an input loop if the user didn't insert what he should, in example like in passwords. i want to make typing the wrong characters would ask the user to try again inserting the right one.

2nd Mar 2020, 11:19 PM
Light
Light - avatar
12 Réponses
+ 6
Remove the break statement from the loop. And put the print("successfully signed in.") outside the else statement. password = input("it's the time to set for your self a new password : ") pass_w = (input("please enter your password to sign in : ")) while pass_w != password: pass_w = (input("sorry your password doesn't match try again : ")) print ("successfully signed in.")
2nd Mar 2020, 11:39 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 5
What have you tried? Just think about it for a little time, it shouldn't be hard. Hint: use a while loop.
2nd Mar 2020, 11:28 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 5
MKgd usually break is used when you have a while True loop, but in most cases you do not use break at all, because the condition is verified before running the loop.
2nd Mar 2020, 11:40 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 4
Here is a better hint: while the input is wrong, you keep retaking the input.
2nd Mar 2020, 11:35 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 3
MKgd and sorry for not responding first. It's better to see what others do even if entirely wrong. Good job 👌
2nd Mar 2020, 11:43 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 3
Aymane Boukrouh [INACTIVE] this was a respond it self, and it was pretty helpful
2nd Mar 2020, 11:44 PM
Light
Light - avatar
+ 2
i ve tried while loop im just missing somthing about it let me get the code here
2nd Mar 2020, 11:34 PM
Light
Light - avatar
+ 2
password = input("it's the time to set for your self a new password : ") pass_w = (input("please enter your password to sign in : ")) while pass_w != password: pass_w = (input("sorry your password doesn't match try again : ")) break else: print ("successfully signed in.")
2nd Mar 2020, 11:37 PM
Light
Light - avatar
+ 2
god , it's the break i was doubting it, but maybe what confused me is that at first i tried to make it with print instead of calling the var
2nd Mar 2020, 11:39 PM
Light
Light - avatar
+ 2
thank you a lot ❤
2nd Mar 2020, 11:40 PM
Light
Light - avatar
+ 2
You can still use a break if you have a while loop for the password not matching, with an if statement inside of that while loop so the password can match, then outside of that say "successfully signed in" like you already have. password = input("it's the time to set for your self a new password : ") pass_w = (input("please enter your password to sign in : ")) while pass_w != password: If pass_w == password: break pass_w = (input("sorry your password doesn't match try again : ")) print ("successfully signed in.")
4th Mar 2020, 6:19 PM
sudo-asap
sudo-asap - avatar
+ 1
sudo-asap thanks man ! enlightened
5th Mar 2020, 3:53 AM
Light
Light - avatar