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

Ali Dahud
Ali Dahud
3,459 Points

is it alright the way I have done it?

import random

secret_num=random.randint(1,10)

answer=""

def play_game():

number_of_guesses = 1

while number_of_guesses<5:

    try:

        guess=int(input("Enter a guess between 1-10: "))

    except ValueError:

        print("A Number pllease!")

    else:

        if guess>secret_num:

            print("you entered too high!")

        if guess<secret_num:

            print("you entered too low!")

        if guess==secret_num:

            print("you guessed it right the number was: {}".format(secret_num))

            break

    number_of_guesses+=1

answer = input("Enter Done if you're done playing: ")

if answer=="Done":

    print("Thank you for playing!")

else:

    play_game()

play_game()

AND WHAT'S the purpose of creating a game that loops until forever if we want it if we guessed the number already?