Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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 28,720 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)