+ 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.
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.")
+ 5
What have you tried? Just think about it for a little time, it shouldn't be hard. Hint: use a while loop.
+ 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.
+ 4
Here is a better hint: while the input is wrong, you keep retaking the input.
+ 3
MKgd and sorry for not responding first. It's better to see what others do even if entirely wrong. Good job 👌
+ 3
Aymane Boukrouh [INACTIVE] this was a respond it self, and it was pretty helpful
+ 2
i ve tried while loop im just missing somthing about it
let me get the code here
+ 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.")
+ 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
+ 2
thank you a lot ❤
+ 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.")
+ 1
sudo-asap thanks man ! enlightened