0

I'm working on a very simple game. I can't figure out how to re run the while loop if the player wants to play again. I tried making the loop into a function but that just ruins my code for some reason. Thank you!

import random

print ("Welcome to numbfy! Try to guess the correct number! Guess a number between 0 and 10! Enter anything but a letter to exit!")

the_num = random.choice(range(0, 11))


while True:
    try:
        guess = int(input("What's your guess? "))
    except ValueError:
        print ("That's not a number!")
        break

    if guess == the_num:
        print ("You guessed it!")
        break
    elif guess > the_num:
        print ("Go lower!")
    elif guess < the_num:
        print ("Go higher!")
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Rimex
  • 17
  • 2

0 Answers0