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 Introduction

Game not posing question

Hi all

I've not been able to get this little script running. I follow the exact process as the teacher in the video. However when I'd like to run it in the console and input the file name, nothing happens. The game does not ask me the first question " Guess a number between 1 and 10: "

import random

# generate random number between 1 and 10
secret_num = random.randint(1, 10)

while True: 
    # get a number guess from the payer
    guess = int(input("Guess a number between 1 and 10: "))

    # compare guess to secret number
    if guess == secret_num:
        print("You got it! My number was {}".format(secret_num))
        break
    else:
        print("That's not it!")

3 Answers

Hi Kevin,

Are you remembering to put python before the file name in the console? Like this:

python my_file.py

The console needs to know what program to run the file in!

Tayler

Hi Tayler,

Without trying to sound arrogant but of course I did. When I am running the older files created (shopping list etc), these work fine.

Haha I was just covering all the bases! Sorry if I insulted your intelligence.

That's weird though, I just opened this up in a workspace and it ran perfectly.

Sounds silly again but have you saved the file before trying to run it?

Haha, no worries, I'm not at all.

That second suggestion did the trick even though I am positive I saved it already. I'm a bit puzzled though as it did not show a red star indicating it wasn't saved though.