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

Rasmus Andersen
Rasmus Andersen
1,569 Points

I cant seem to figure out what's wrong with this script. i tried to write what kenneth wrote

here's the script: import random

Safely make an int

Limit guesses

Too high message

Too low message

Play again feature

def game(): # Generate a random number between 1 and 10 secret_num = random.randint(1, 10) guesses = []

while len (guesses) < 5:
    try:
    # get a number guess from the player
        guess = int(input("""Guess a number between 1 and 10
    >>>  """))
    except ValueError:
        print("{} isn't a number".format(guess))
    else:

        # compare guess to secret number
        if guess == secret_num:
            print("Correct, you're quite the guesser")
            break
        else:
            ("WRONG!")
        guesses.append(guess)
        # print hit or miss

Btw dont mind the comments

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 23,332 Points

Pretty close to being correct... all you need to do is add a print before ("WRONG!")

        if guess == secret_num:
            print("Correct, you're quite the guesser")
            break
        else:
            print("WRONG!") # adding the print here will make it work
        guesses.append(guess)