Python Python Basics (2015) Number Game App Number Game Refinement

Abdullah Jassim
Abdullah Jassim
4,551 Points

Feedback on below code?

import random



def game ():

random_number = random.randint(1, 10)
guesses = []

  while len(guesses) < 5: 
    try:
      guess = int(input("Guess a number between 1 and 10: "))
    except ValueError:
      print("{} isnt a number!".format(guess))
    else:
      if guess == random_number:
        print("You got it! My number was {}".format(random_number))
        break
      elif guess > random_number:
        print("Too high! Guess again. You have " +str(len(guesses)) + " remaining")
      else: 
        print("Too low! Guess again. You have " +str(len(guesses)) + " remaining")
      guesses.append(guess)
else:
    print("Game over! My number {}".format(random_number))
play_again = input("Do you wanna play again? Y/N ")
  if play_again != "N":
    game()
  else:
    print("Bye")


game()