【发布时间】:2018-06-10 19:09:46
【问题描述】:
我仍然是 Python 的初学者,目前正在使用 codecademy。我决定将其中一个练习程序稍微复杂化,我遇到了这个错误:
Traceback (most recent call last):
File "python", line 30, in <module>
File "python", line 24, in trip_cost
File "python", line 18, in rental_car_cost
TypeError: unsupported operand type(s) for -: 'unicode' and 'int'
这是我的代码:
def hotel_cost(nights):
# the hotel costs $140 per night
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):
cost = days * 40
if days >= 7:
cost -= 50
elif days >= 3 and days < 7:
cost -= 20
return cost
def trip_cost(city, days, spending_money):
return rental_car_cost(days) + hotel_cost(days - 1) + plane_ride_cost(city) + spending_money
x = raw_input("Where are you going? ")
y = raw_input("How many days are you going for? ")
z = raw_input("How much spending money are you taking? ")
print trip_cost(x, y, z)
任何帮助将不胜感激,谢谢!我是初学者,所以我的 python 术语有点生疏。
【问题讨论】:
标签: python python-2.7