Build a Movie Ticket Booking Calculator - Step 21

Tell us what’s happening:

I am not sure what is going on. I have been trying to get this last step figured out but I keep getting the error of “Declare a variable named final_price”. I thought I had the variable declared but I can’t seem to find my mistake. I am a first time coder and I am feeling pretty defeated by this. Can someone please help?

Your code so far

base_price = 15
age = 21
seat_type = 'Gold'
show_time = 'Evening'

if age > 17:
    print('User is eligible to book a ticket')

if age >= 21:
    print('User is eligible for Evening shows')
else:
    print('User is not eligible for Evening shows')

is_member = False
is_weekend = False

discount = 0
if is_member and age >= 21:
    discount = 3
    print('User qualifies for membership discount')
else:
    print('User does not qualify for membership discount')
print('Discount:', discount)

extra_charges = 0
if is_weekend or show_time == 'Evening':
    extra_charges = 2
    print('Extra charges will be applied')
else:
    print('No extra charges will be applied')
print('Extra charges:', extra_charges)

if age >= 21 or age >= 18 and (show_time != 'Evening' or is_member):
    print('Ticket booking condition satisfied')

    service_charges = 0
    if seat_type == 'Premium':
        service_charges = 5
    elif seat_type == 'Gold':
        service_charges = 3
    else:
        service_charges = 1
    print('Service charges:', service_charges)

# User Editable Region

final_price = 0
final_price = base_price + extra_charges + service_charges - discount
print('Final price of ticket:', final_price)    

# User Editable Region


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36

Challenge Information:

Build a Movie Ticket Booking Calculator - Step 21

It seems like you are declaring that variable twice. Do you need to set it to zero first?

At the bottom of your last if statement body,

Make sure it’s in the if statement body.

Thank you so much! I got it!

1 Like

I had the same issue. Figured it out. Just wondering what the explanation is for why it must be in the last ‘if’ statement? It’s pulling information from multiple ‘if’ statements which makes me assume it can be it’s own separate statment.

thanks for your help

@BobbyD

The main reason I suggested it is how it’s described in the instructions:

At the bottom of your last if statement body,

Not “after” the if statement, but at the bottom of the body, which means add it within the if statement.

For the logic, look at the structure of the if statement here:

if age >= 21 or age >= 18 and (show_time != 'Evening' or is_member):
    print('Ticket booking condition satisfied')
    ...
    print('Final price of ticket:', final_price) 
    
else:
    print('Ticket booking failed due to restrictions')

We are in the middle of an if/else structure.

if conditions are satisfied we want to print the final price.
else we want to print “failed”

So, calculating and printing the final price should be within the if.

Also… if it isn’t in the if statement:

if age >= 21 or age >= 18 and (show_time != 'Evening' or is_member):
    print('Ticket booking condition satisfied')
    ...
print('Final price of ticket:', final_price) 
#if statement is finished when the indentation ends.
    
else:
    print('Ticket booking failed due to restrictions')

Now the if statement is broken. It ends when the indentation ends and then there is a stray else at the bottom not connected to the if above.

Good question, I hope this answers it for you?

1 Like