很抱歉打扰你一个noob问题,但我是Python新手。基本上这是一个家庭作业,我不明白我做错了什么。我想我需要的东西都有了,但我老是打字出错。感谢任何帮助。谢谢!在
def Main():
Weight = float(input ("How much does your package weigh? :"))
CalcShipping(Weight)
def CalcShipping(Weight):
if Weight>=2:
PricePerPound=1.10
elif Weight>=2 & Weight<6:
PricePerPound=2.20
elif Weight>=6 & Weight<10:
PricePerPound=float(3.70)
else:
PricePerPound=3.8
print ("The total shipping cost will be $%.2f") % (PricePerPound)
Main()
print()
函数返回None
;您可能希望将%
操作移动到函数调用中:请注意,} ;您可能希望使用^{} ,使用布尔逻辑:
^{pr2}$if
测试使用的是bitwise and operator ^{或者,使用比较链接:
检查您的测试,您测试
Weight >= 2
太早;如果Weight
介于2和6之间,您将匹配第一个if
,并完全忽略其他语句。我想你想要:价格是1.10英镑,除非你有一个重量为2英镑或2英镑以上的包裹,否则价格会逐步上涨。在
相关问题 更多 >
编程相关推荐