2015-03-05 5 views
1

У меня есть быстрый вопрос для всех вас. В настоящее время я работаю над типовой системой бронирования авиакомпаний, и у меня возникают трудности с отображением общей суммы дисконтированных, если пользователь является часто летающим пассажиром (10% скидка). Ниже приводится мой код:Применять скидку и показывать скидку в Python 2.7

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!') 

Пока я не получаю сообщение об ошибке, мой результат неправильный. Это то, что отображается:

Discount amount of 1738.8 

Это явно неверно, так как это цена после скидки. Я пытаюсь показать общую сумму СКИДКИ, а также цену ПОСЛЕ того, как была применена скидка.

Любая помощь будет оценена! Благодаря!

+0

Что вы вводите – Backtrack

ответ

3

У вас есть несколько ошибок. Во-первых, в else первого if, вы сделать не вычислительных seat_total, поэтому следующие вычисления будут врезаться - вы просто делаете

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

, а не явно нужен

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

(круглые скобки бесполезны, но они не болят, поэтому я позволяю им быть :-).

Во-вторых, посмотрите на свою логику скидок:

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 

Вы хотите сказать, что очень явно, что со скидкой пользователь платит 1/10th из прайс-листа - тогда вы жалуетесь об этом в ваш Q -!)

это, опять же, очевидно (для людей, читающих между строк - никогда, конечно, к компьютерам :-), что резко контрастирует с тем, что вы сказать, что вы на самом деле значит есть:

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 
+0

Фантастический, спасибо Alex! Узнал много! – Lukon

Смежные вопросы