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

I AM not able to loop if ticket asked is more

TICKET_PRICE = 10
import sys

tickets_remaing = 100
while tickets_remaing >= 1:
    # output how many tickets are remaining using the tickets_remaining varaiable

    print('The Number of Ticket Remaning is {}'.format(tickets_remaing))

#aking user name and asking them for ticktes they need

    asking_name = input('What is Your Good Name: ')
    print('Hi {}'.format(asking_name))
    try:
        need_ticket = int(input('Number of Ticket Do You Want: '))
        if need_ticket > tickets_remaing:
            raise ValueError('sorry we do not have sufficient ticket {}'.format(tickets_remaing))
    except ValueError as err:
        print('Oops please type the numbers and try again: ')

#calculate and tell totla price of tickets

        calculate = int(TICKET_PRICE * need_ticket)

        print('Totla price of Your ticket is ${}'.format(calculate))

#we need user to ask did they want to proceed or not mean y/n

        asking_proceed = input('Did You Want To Proceed if yes press "y" if not press "n": ')

        if asking_proceed.lower() == ('y'):
            print('\n                    S O L D ! ! !              ')
            print('\n            Thanks for Purchasing  {}'.format(asking_name))
        tickets_remaing -= need_ticket
sys.exit('\n          sorry all ticket has been s o l d !!!!               ')

1 Answer

It looks like your code currently has an issue with its indentation.

except ValueError as err:
        print('Oops please type the numbers and try again: ')

#calculate and tell totla price of tickets

        calculate = int(TICKET_PRICE * need_ticket)

All of your code after except ValueError as err: and before sys.exit('\n sorry all ticket has been s o l d !!!! ') will occur only if there is a ValueError. You could try adding else: at the same indentation level as try: and except ValueError as err: after dealing with the ValueError.