2

I need some help, you know those "repeat until" blocks in scratch? Well I need to know how to do that in python. What I want to do is this, with a repeat block.

retry = True if password = "password1234": retry = False else: pass 
5
  • so you want to be in a loop untill password == "password1234" , is my understanding correct? Commented May 6, 2022 at 20:40
  • 1
    A do-while loop will solve that... Commented May 6, 2022 at 20:41
  • @kenntnisse "do-while"? In Python? Did I miss something? Commented May 6, 2022 at 20:45
  • I want to put this whole code in a "repeat until" block. Commented May 8, 2022 at 2:55
  • @VMSMani Yes, but I have some code "password = input("What's your password?")" and then I want the variable password to save(Permently, even if you reboot the program.), so then when you put it in... ITS BASICLLY A SIGN IN PAGE, OK? Commented May 8, 2022 at 2:59

3 Answers 3

1

The following snippet checks if the password is "password1234". If it is correct, it changes the flag to False and hence the loop terminates. Otherwise, it will do further processing (e.g., ask the user for a new input).

retry = True password = "" while (retry): # Check if the password equals to a specific password. if (password == "password1234"): retry = False else: # Do further processing here. # Example: ask the user for the password password = input("Enter a password: ") 
Sign up to request clarification or add additional context in comments.

Comments

0

Program will be asking you for password until you type password1234

password = input("Enter you password") while password!="password1234": password = input("Enter you password") 

1 Comment

wow this is the most shortest one ive seen, +15 social credit points
0

The above solutions are also correct. But if you want to keep your style, try this:

def get_password(): retry = True password = input("Password: ") if retry: if password == "password1234": retry = False else: return get_password() get_password() 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.