I have seen some similar questions getting the answer to use a while-loop instead to "go back" in if-statements but i still trying to figure out how it all works. From the examples i've seen so far, it seems like you should set a variable to False
and keep looping as long as the condition of that is "True", but i don't get it really, probably understood it completely wrong. I have some examplecode below with comments where i would want to be able to "go back" in statements but i have no idea how to actually achieve that
welcome = "If you choose to accept, you will get a list of options below. Do you accept the terms?"
terms = "" # True/False according to below
username = input("Enter your username: ")
if not username:
print("You haven't entered a username! " + username) # Here i would want it to start over if no username is specified
else:
print("Hello, " + username + "\n" + welcome)
choise_terms = input("(yes/no)")
if choise_terms == "no":
terms == False
elif choise_terms == "yes":
terms == True
else:
print("You have to type either \"yes\", or \"no\", do you accept the terms? " + choise_terms) # Here i would want it to start over if either "yes" or "no" is specified
# Continue the program if terms are accepted, else close the application
So from what i understand i should be able to put my if statement inside of a whileloop somehow, and as long as yet another variable is set to True
, the loop will continue?