【发布时间】:2016-02-01 22:24:14
【问题描述】:
我需要帮助我得到的错误是未定义成本。该程序根据运输类型和重量计算邮政费率。我不确定我做错了什么,一些建议将非常感谢
def main() :
'''The program calculates the cost of postal rates through the type of
shipping and the weight of the package'''
Shipping = int(input("Shipping: Enter (1) stamps or (2) for meter postage: "))
Size = int(input("Package size: Enter (1) for standard size or (2) for
oversize: "))
Weight = int(input("What is the weight in grams of the envelope?: "))
#Standard shipping
if Shipping == "1" :
if Size == "1" :
if weight <= 30 :
cost = "1.00"
elif weight >=31 <=50 :
cost = "1.20"
if Shipping == "2" :
if Size == "1" :
if weight <= 30 :
cost = "0.77"
elif weight >=31 <=50 :
cost = "1.18"
#Oversize shipping
if Shipping == "1" :
if Size == "2" :
if weight <= 100 :
cost = "1.80"
elif weight >101 <=200 :
cost = "2.95"
elif weight >=201 <=300 :
cost = "4.10"
elif weight >=301 <=400 :
cost = "4.70"
elif weight >=401 <=500 :
cost = "5.05"
if Shipping == "2" :
if Size == "2" :
if weight <= 100 :
cost = "1.65"
elif weight >101 <=200 :
cost = "2.68"
elif weight >=201 <=300 :
cost = "3.76"
elif weight >=301 <=400 :
cost = "4.27"
elif weight >=401 <=500 :
cost = "4.58"
#Print the answer
print("This shipment will cost you ${0:.2f}".format(cost))
main()
【问题讨论】: