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 All Together Now Handle Exceptions

Indentation Error

I receive this error: "unindent doesn't match any outer indentation level" I even deleted my code and practically copied the instructor's code. I still get this error. Can you see what I am doing wrong?

TICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining>=1:
    print("There are {} tickets left.".format(tickets_remaining))
    name = input("Hello! What is your name?")
    num_tickets = int(input("Hi {}! How many tickets would you like to buy?".format(name)))
    try:
        num_tickets = int(num_tickets)
    except ValueError:
        print("This is not a valid number. Please try again")
    else:
        amount_due = num_tickets * TICKET_PRICE
        print("The amount due is £{}.".format(amount_due))
        should_proceed = input("Do you want to proceed? Y/N ")
        if should_proceed.lower() == "y":
            print("Thank you for your purchaise. Have a great day {}!".format(name))
            tickets_remaining-=num_tickets
        else:
            print("Thank you anyway. Enjoy your day!")  
else:
    print("Sorry! The tickets are all sold out.")

Mod Edit: Fixed code formatting, see comment for how to use code markdown.

I found the issue. Thank you!

rydavim
rydavim
18,776 Points

When code formatting on the forums, remember to use backticks - which are usually found on the ~ key. Happy coding!

```language

Your code here!

```

// Your code here!

1 Answer

Garren Ijames
Garren Ijames
945 Points

Hi Ioana, Errors like this can sometimes occur when the white-space character used for indentation is inconsistent (for example tabs that are used on one line, and spaces that are used on another). You might try removing all indentation from your example, and then reapplying it with your own text-editor, code-editor, or IDE. Let me know if this fixes your error.

Cheers