Python Python Basics All Together Now Handle Exceptions

ioana morosanu
ioana morosanu
1,557 Points

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.

ioana morosanu
ioana morosanu
1,557 Points

I found the issue. Thank you!

rydavim
rydavim
Treehouse Moderator 16,911 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