这是一个返回旅行费用的Python函数。我无法弄清楚这有什么问题 - 什么都没有被调用。我错过了什么吗?
def hotel_cost(nights):
return 140 * nights
def plane_ride_cost(city):
if city == "Charlotte":
return 183
elif city == "Tampa":
return 220
elif city == "Pittsburgh":
return 222
elif city == "Los Angeles":
return 475
def rental_car_cost(days):
total_car = days * 40
if days >= 7:
total_car -= 50
elif days >= 3:
total_car -= 20
return total_car
def trip_cost(city, days):
return rental_car_cost(days) + plane_ride_cost(city) + hotel_cost(days)
print trip_cost("Charlotte", 6)
答案 0 :(得分:0)
写
print trip_cost("Charlotte", 6)
您正在调用函数'trip_cost'并获取返回值,但您没有对返回值执行任何操作。要查看输出,请使用print
答案 1 :(得分:0)
以下代码适用于我并返回1243:
def hotel_cost(nights):
return 140 * nights
def plane_ride_cost(city):
if city == "Charlotte":
return 183
elif city == "Tampa":
return 220
elif city == "Pittsburgh":
return 222
elif city == "Los Angeles":
return 475
def rental_car_cost(days):
total_car = days * 40
if days >= 7:
total_car -= 50
elif days >= 3:
total_car -= 20
return total_car
def trip_cost(city, days):
return rental_car_cost(days) + plane_ride_cost(city) + hotel_cost(days)
print(trip_cost("Charlotte", 6))
我刚删除了一些无用的缩进并添加了“打印”