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 (Retired) Pick a Number! Any Number! The Solution

What am I doing wrong? Python Number game challenge

It says there is invalid syntax on line 18( the break) and when I take that out it says there is invalid syntax on line 19(the else statement)

import random

secret_number = random.randint(0, 100)
guessed_nums = []
hint = print("Guess a number between 1 and 100")
question = input("What is your number? ")

  print("Thats not a whole number")


if secret_number == player_num:
  print("You win!It took you {} tries".format(guessed_nums)
  if secret_number > new_int:
    print("Nope! My number is higher than {}. Guess #{}".format(player_num, len(guessed_nums)))
    print("Nope! My number is lower than {}. Guess #{}".format(player_num,  len(guessed_nums)))


1 Answer

Hi Arjun,

I went ahead and fixed your code formatting for you. See this thread: https://teamtreehouse.com/forum/posting-code-to-the-forum

I don't see your loop but it looks like you meant to have one with the break and continue statements.

In your print statement right before that else: you don't have the closing parenthesis for the print function.