I am making number guesser program and I am trying to figure out how to restart this if you get the number wrong. I have tried while true loops and It just keeps asking the question. I need some help with this thanks (python). EDIT: j1-lee answered question very good!
import random
ask = input("Guess a number between 0 and 10")
r1 = random.randint(0, 1)
print("The number is % s" %(r1))
if int(ask) == r1:
print("right")
else:
print("wrong")
>Solution :
Your while True approach was right. You only need to add break at an appropriate place:
import random
while True:
ask = input("Guess a number between 0 and 10: ")
r1 = random.randint(0, 10)
print(f"The correct number is {r1}.")
if int(ask) == r1:
print("... and you were right!")
break
else:
print("Try again!")