c = random.randint(0,5)
guess =int(input("="))
while True:if guess > c:print("you failed the test")elif guess <c: print("you messed up")else:print("you are the one" + x)break
c = random.randint(0,5)
guess =int(input("="))
while True:if guess > c:print("you failed the test")elif guess <c: print("you messed up")else:print("you are the one" + x)break
You can use break
in more than one place in the loop. It doesn't have to be in else
block or anywhere in particular. This will still work:
c = random.randint(0,5)
guess =int(input("="))
while True:if guess > c:print("you failed the test")breakelif guess <c: print("you messed up")breakelse:print("you are the one" + x)break
This code doesn't make much sense though as the loop will never run a second time. You probably want to ask for input every time the loop runs. So you should move the input()
call into the loop as well. It seems like you're looking for:
c = random.randint(0,5)
while True:guess =int(input("="))if guess > c:print("you failed the test")elif guess <c: print("you messed up")else:print("you are the one" + x)break