mercredi 4 mars 2015

Printing a subtotal when a value is defined inside an if-elif-else statement? Name error issue [Python 2.7]

I'm currently working on a project which acts as an airline reservation booking system. As of right now I'm having an issue with calculating and displaying a subtotal which was calculated inside of an if elif else loop statement, if that makes sense.


For example, I currently need to calculate the subtotal of the seats and luggage. Below is my code:



user_people = int(raw_input("Welcome to Ramirez Airlines! How many people will be flying?"))
user_seating = str(raw_input("Perfect! Now what type of seating would your party prefer?"))
user_luggage = int(raw_input("Thanks. Now for your luggage, how many bags would you like to check in?"))
user_frequent = str(raw_input("Got it. Is anyone in your party a frequent flyer with us?"))
user_continue = str(raw_input("Your reservation was submitted successfully. Would you like to do another?"))
luggage_total = user_luggage * 50


import time
print time.strftime("Date and time confirmation: %Y-%m-%d %H:%M:%S")

if user_seating == 'economy':
seats_total = user_people * 916
print seats_total

elif user_seating == 'business':
seats_total = user_people * 2650
print seats_total

else:
print user_people * 5180

print luggage_total

print luggage_total + seats_total


As I said above I'm trying to add the total price for the number of plane tickets reserved based on which class the user chose (economy, business and first class) and the total amount of the required luggage needed to be checked in (x amount & $50).


This is the error I am receiving when executing the above code:



Traceback (most recent call last):
File "C:/Users/Cory/Desktop/Project 1.py", line 26, in <module>
print luggage_total + seats_total
NameError: name 'seats_total' is not defined


How do I go about defining seats_total outside of the if-elif-else statements?


Thank you so much!


Aucun commentaire:

Enregistrer un commentaire