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
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
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: ")
Program will be asking you for password until you type password1234
password = input("Enter you password")
while password!="password1234":
password = input("Enter you password")
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()