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 Python Basics All Together Now Branch and Loop

The 'if' statement is not showing up when the program is run

If they want to proceed

if should_proceed.lower() == 'y':
    #print out to screen,SOLD to confirm purcahse
    print('SOLD! Your transaction has been approved.')
    #ENter credit card 
    #then decrease the tickets remaining by number of tickets purchased
    tickets_remaining -= num_tickets

this is what my code looks like and for some reason the if statement isn't running

TICKET_PRICE = 10

tickets_remaining = 100

Output how many ticets are left using tickets_remaining variable

print('There are {} tickets remaining.'.format(tickets_remaining))

Get users name and assign to new variable

name = input('What is your name? ')

Prompt user by name, ask how many tickets they want

num_tickets = input('How many tickets would you like, {}? '.format(name)) num_tickets = int(num_tickets)

Calculate the price (number of tickets wanted * price of one ticket(10))

cost = num_tickets * TICKET_PRICE

Output price to the screen

print('Total due is £{}.'.format(cost))

prompt user if they want to proceed

should_proceed = input('Would you like to proceed? Yes or No. ')

If they want to proceed

if should_proceed.lower() == 'Y':

#print out to screen,SOLD to confirm purcahse
print('SOLD! Your transaction has been approved.')
#ENter credit card 
#then decrease the tickets remaining by number of tickets purchased
tickets_remaining -= num_tickets
print('There are {} remaining.'.format(tickets_left))

otherwise...

else: #THank yhem by name print('Thank you {}.'.format(name))

2 Answers

Scott Bailey
Scott Bailey
13,177 Points
print('There are {} remaining.'.format(tickets_left))

This should be

print('There are {} remaining.'.format(tickets_remaining))

Also

if should_proceed.lower() == 'Y':

You should have a lowercase 'y' as you've called .lower()

if should_proceed.lower() == 'y':

After these changes and correct indenting your code should work fine.

TICKET_PRICE = 10

tickets_remaining = 100

print('There are {} tickets remaining.'.format(tickets_remaining))

name = input('What is your name? ')

num_tickets = input('How many tickets would you like, {}? '.format(name))
num_tickets = int(num_tickets)

cost = num_tickets * TICKET_PRICE

print('Total due is £{}.'.format(cost))

should_proceed = input('Would you like to proceed? Yes or No (Y/N). ')

if should_proceed.lower() == 'y':

    #print out to screen 'SOLD' to confirm purcahse
    print('SOLD! Your transaction has been approved.')
    #Enter credit card
    #Then decrease the tickets remaining by number of tickets purchased
    tickets_remaining -= num_tickets
    print('There are {} remaining.'.format(tickets_left))

else: #Thank them by name
    print('Thank you {}.'.format(name))
Scott Bailey
Scott Bailey
13,177 Points

Could you post your full code?

I can't see why this wouldn't work, perhaps something before is causing the issue?