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

Rondeep Barua
Rondeep Barua
746 Points

Why do I get an indentation error on the last line of code?

Probably missing something simple :/

TICKET_PRICE = 10

tickets_remaining = 100 


while tickets_remaining >= 1:
    print('There are {} tickets remaining!'.format(tickets_remaining))
    user_name = input('What is your name?   ')
    number_of_tickets = input('Hello {}! How many tickets would you like?   '.format(user_name))
    try:
        if not number_of_tickets.isdigit():
            raise ValueError('Please enter a valid whole number between 1 and {}'.format(tickets_remaining))
        number_of_tickets = int(number_of_tickets)
        if number_of_tickets > tickets_remaining:
            raise ValueError('There are only {} tickets remaining'.format(tickets_remaining))
        else:    
            price = number_of_tickets * TICKET_PRICE 
            print('That will cost £{}'.format(price))
            proceed = input('Do you want to procced, Y/N?   ')
            if proceed.lower() == 'y':       
                # TODO: Gather credit card information and process it.
                print('SOLD!')    
                tickets_remaining -= number_of_tickets  
            else:   
                print('Thank you anyways, {}!'.format(user_name))
print('Sorry {} but the tickets are now sold out.'.format(user_name))

Thanks in advance

2 Answers