while True:
    restart=False
    userguess=int(input("guess"))
    if userguess not in range(0,100):
          restart=True
          break     
    if userguess>computerguess:
          print("guessed higher")
    elif userguess<computerguess:
          print("guessed lower")
    else:
          print("congrats, userguess equals computerguess")
          break

/* i want to loop to break if guess number is out of 0 to 100 range. It works. But after that,i want user input is again asked and if next value is within range, i want loop to restart.Please help*/

1 Answers

0
Community On

Use continue instead of break

while True:
    restart=False
    userguess=int(input("guess"))
    if userguess not in range(0,100):
          restart=True
          break     
    if userguess>computerguess:
          print("guessed higher")
    elif userguess<computerguess:
          print("guessed lower")
    else:
          print("congrats, userguess equals computerguess")
          continue