+ 3

How can I make an if statement run the number of times the condition occurs?

I'm making a login form with python. And I put a condition for the password. If the pass is less than 8 it should print your password should be 8 or more 8 characters. But it only prints once. And if the user repeats the same mistake it does nothing. What can I do?

25th Jun 2020, 2:39 PM
Chinyere Unamba
Chinyere Unamba - avatar
6 Réponses
+ 8
Input your code in a loop, while loop specifically
12th Jul 2020, 7:37 PM
Goke Ekundayo
Goke Ekundayo - avatar
+ 7
Put a while loop around your code: while True: psw= input("Enter your password or x to terminate: ") if psw.lower() == 'x': print('terminating ...') break elif len(psw) < 8: continue else: print('your input was ok') break
25th Jun 2020, 5:33 PM
Lothar
Lothar - avatar
+ 4
That's where loops come into picture. Learn about it here👇 https://www.geeksforgeeks.org/loops-in-JUMP_LINK__&&__python__&&__JUMP_LINK/
25th Jun 2020, 2:41 PM
Arsenic
Arsenic - avatar
+ 3
Run your code under the while loop. bool=true while bool: if len(psw) < 8: #do your stuff else: bool=false #do your stuff
25th Jun 2020, 2:43 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 1
https://code.sololearn.com/cIVlwCBP9iC2/?ref=app This is a part of the form I just had to type it here in solo learn playground.
25th Jun 2020, 4:57 PM
Chinyere Unamba
Chinyere Unamba - avatar