使用python 2.7.5,解決編程類問題,其中訂單總額被添加到運輸成本,價格被設置爲運送到美國和加拿大,我寫有代碼運送到美國但需要更改值,因此如果用戶選擇加拿大,則將不同的一組值應用於訂單總額。 加拿大運費:8.00小於50.0,12.0超過50.01 - 100.0,15.0 100.01 - 150.0,我需要一種方法,在下面的代碼在美國國內運費替換這些值:python多if/elif/else語句並僅顯示用戶選擇
user_order = float(input("how much is your order? "))
user_ship_area = raw_input('Are you shipping to the US or Canada?')
if user_order < 50.00 and user_ship_area == "US": #start selection with user order and shipping area.
#User would be given price for shipping according to order cost
print 'you must pay $6.00 for shipping ' #user order less than 50$ = 64 for shipping.
user_order = user_order + 6.0
elif user_order <100.0> 50.01 and user_ship_area == "US": #must include range of numbers, if user order is over 50.01 but under 100.0
print 'you must pay $9.00 for shipping' #they must pay 9.00 for shipping.
user_order = user_order + 9.0
elif user_order <150.0> 100.01 and user_ship_area == "US": #if user order is over 100.01$ but under 150$
print 'you must pay $12.00 for shipping '#12.00$ will be charged for shipping
user_order = user_order + 12.0
else:
print 'congratulations you qualify for free shipping' #since it works by checking each elif, it goes to else
print "your order total is", user_order
#need to create option for shipping to Canada, the prices are different.
#how to repeat the above code but for different values if the user selects Canada.
請正確縮進您的代碼。 – thefourtheye