1

I have a quick question for you all. I'm currently working on an sample Airline reservation system and I'm having difficulties displaying the total amount discounted if the user is a frequent flyer (10% discount rate). 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")

seats_total = 0

if user_seating == 'economy':
    seats_total = user_people * 916
    print ('The total amount for your seats is: $'),seats_total

elif user_seating == 'business':
    seats_total = user_people * 2650
    print ('The total amount for your seats is: $'),seats_total

else: 
    print ('The total amount for your seats is: $'),user_people * 5180

print ('The total amount of your luggage is: $'),luggage_total

print ('Your subtotal for your seats and luggage is $'), luggage_total + seats_total

discount_amount = 0
discount_rate = 0.10

if user_frequent == 'yes':
    before_discount = luggage_total + seats_total
    after_discount = before_discount * discount_rate
    discount_amount = before_discount - after_discount
    print discount_amount

else:
    print ('Sorry, the discount only applies to frequent flyers!')

While I'm not receiving an error, my output is incorrect. This is what is being displayed:

Discount amount of 1738.8

This obviously is incorrect as that is the price after the discount. I'm trying to display the total DISCOUNT as well as the price AFTER the discount has been applied.

Any help would be appreciated! Thanks!

Lukon
  • 255
  • 4
  • 20

1 Answers1

3

You have more than one bug. First, in the else of the first if, you don't compute seat_total, so following computations will crash -- you just do

print ('The total amount for your seats is: $'),user_people * 5180

rather than the obviously needed

seat_total = user_people * 5180
print ('The total amount for your seats is: $'), seat_total

(the parentheses are useless but they don't hurt so I'm letting them be:-).

Second, look at your logic for discounts:

discount_rate = 0.10

if user_frequent == 'yes':
    before_discount = luggage_total + seats_total
    after_discount = before_discount * discount_rate
    discount_amount = before_discount - after_discount

You're saying very explicitly that with a discount the user pays 1/10th of the list price -- then you complain about it in your Q!-)

It is, again, obvious (to humans reading between the lines -- never of course to computers:-), that in sharp contrast to what you say, what you actually mean is:

discount_rate = 0.10

if user_frequent == 'yes':
    before_discount = luggage_total + seats_total
    discount_amount = before_discount * discount_rate
    after_discount = before_discount - discount_amount
Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395