Build a Movie Ticket Booking Calculator - Step 21

Hi,

I’m not able to continue through with step 21. I’m failing one of the conditions in the console. That is :

1. You should declare a variable named final_price.

I’ve tried declaring the variable at the very start of the code and again at the bottom with a:

final_price = 0

When I run it in VS Code it’s fine. It’s only when the test environment that’s giving me this issue. Code as follows:

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) 
else:
    print('Ticket booking failed due to restrictions')

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

Error message reads:

You should declare a variable named final_price.

Nevermind. Figured out what went wrong. Sorry for any inconvenience!

Corrected code:

removed

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like

Please can you let me know how you fixed yours? MIne is displaying same thing and i have tried for hours but cant seem to fix it

@shekzy

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Help button located on the challenge.

The Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.