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

IndentationError: unindent does not match any outer indentation level

please help me .. I cant figure out what is wrong with my code.

import random

def game():
      secret_number = random.randint(1,2)
      guesses = []
      while len(guesses) < 5:
        try:
            guess = int(input("Guess a number between 1 and 10: "))
        except ValueError:
            print("{} that is not a number, try again".format(guess))
        else:
            if guess == secret_number:
                print("you got it my number was {}".format(secret_number))
                break
            else:
                print("You miss it!")
            guesses.append(guess)


game()
Chris Freeman
Chris Freeman
Treehouse Moderator 68,468 Points

It runs correctly for me. Can you pass the stacktrace dump you are seeing?

1 Answer

Hey Taflah,

looks like you've used the wrong indentation. You have some tabs there and some one space characters. Correct indetation for python is 4 spaces.

Try this:

import random

def game():
    secret_number = random.randint(1,2)
    guesses = []
    while len(guesses) < 5:
        try:
        guess = int(input("Guess a number between 1 and 10: "))
        except ValueError:
            print("{} that is not a number, try again".format(guess))
        else:
            if guess == secret_number:
                print("you got it my number was {}".format(secret_number))
                break
            else:
                print("You miss it!")
            guesses.append(guess)


game()
Chris Freeman
Chris Freeman
Treehouse Moderator 68,468 Points

Interesting! My cut and paste from the OP code must have corrected for the mismatch. Nice work!!

aha. that makes sense .. thank you