Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Abdullah Jassim
Abdullah Jassim
4,551 Points

I get a syntax error everytime I run the script

import random
secret_number = random.randint (1, 10)


while true:
  guess = int(input("Can you guess my number between 1 and 10? "))
  if guess == secret_number:
    print("You got it. The number was {}".format(secret_number))
    break
  else:
    print("Come on you can do better. Guess again! ")

3 Answers

Steven Ang
Steven Ang
41,749 Points

The issue is caused by this piece of code:

while true:

The letter t in true needs to be capitalised or else it won't work. Just fix that then it will work.

while True:
Abdullah Jassim
Abdullah Jassim
4,551 Points

still the same error

import random
secret_number = random.randint (1, 10)


while True:
  guess = int(input("Can you guess my number between 1 and 10? "))
  if guess == secret_number:
    print("You got it. The number was {}".format(secret_number))
    break
  else:
    print("Come on you can do better. Guess again! ")
Steven Ang
Steven Ang
41,749 Points

Did you save your workspaces? I copy-paste your code into workspaces and It works just fine.

Abdullah Jassim
Abdullah Jassim
4,551 Points

I tried doing the number challenge by myself and the below error is what I get when I run the script:

treehouse:~/workspace$ python
Python 3.5.0 (default, Apr 13 2017, 18:07:59)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.

python number_game.py
File "<stdin>", line 1
python number_game.py
^
SyntaxError: invalid syntax

Abdullah Jassim
Abdullah Jassim
4,551 Points

I found out my mistake. I ran the script in the python shell.