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 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,814 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