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

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