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

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,751 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,751 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.