说明
就像上面的示例一样,如果您将7天检查if语句和3天检查elif语句,则此检查会变得更简单。
def rentalcarcost(days):
cost = 40 * days
if days >= 7:
return cost - 50
elif days >= 3:
return cost - 20
else:
return cost
答案 0 :(得分:3)
如果您的代码即使在缩进修复后仍无法正常工作,这是正确的代码:
def car_cost(days):
cost = 40*days
if days>=7:
cost = cost-50
elif days>=3:
cost = cost-20
return cost
PYTHON的压痕事项!
这是你的代码正确缩进。
def rentalcarcost(days):
cost = 40 * days
if days >= 7:
return cost - 50
elif days >= 3:
return cost - 20
else:
return cost