def hotelcost(nights):
cost = 140
return nights * cost
def planeridecost(city):
if city == "Charlotte":
return 183
elif city == "Tampa":
return 220
elif city == "Pittsburgh":
return 222
elif city == "Los Angeles":
return 475
def rentalcarcost(days):
cost = 40 * days
if days >= 7:
cost - 50
elif days >= 3:
cost - 20
else:
return cost
def tripcost(city,days,spendingmoney):
return planeridecost(city) + hotelcost(days) + rentalcarcost(days) + spendingmoney
print tripcost
return tripcost
tripcost("Los Angeles",5,600)
我不能用Python解决这个问题。我尝试了其他几种代码来执行相同的操作,但无法执行:
^{pr2}$
对于days>;=7和days>;=3的情况,Rentalcarcost函数返回None。按如下方式执行:
tripcost函数有两个返回值,第二个返回值无效。在
您的
rentalcarcost()
函数只返回其中一个分支中的cost
值:所以只有当
^{pr2}$days
小于3时,才会返回成本。其他分支也需要包括return
语句,否则将返回None
:相关问题 更多 >
编程相关推荐