【发布时间】:2018-06-06 12:19:10
【问题描述】:
我正在使用 codecademy 的 Python,但在计划假期作业 (7/7) 时遇到了麻烦。
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):
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
city = raw_input('city?')
days = raw_input('days?')
spending_money = raw_input('money?')
print trip_cost(city,days,spending_money)
当我运行脚本并在提示符下输入时,它无法显示以下错误:
Traceback (most recent call last):
File "python", line 28, in <module>
File "python", line 23, in trip_cost
File "python", line 17, in rental_car_cost
TypeError: unsupported operand type(s) for -=: 'unicode' and 'int'
【问题讨论】:
-
遇到麻烦并不能帮助我们帮助您。你有什么问题?你有错误吗?如果你是他们是什么?
-
遇到了麻烦——你很迷茫。您的问题到底是什么,输入参数的预期结果是什么,实际输出是什么。 - 另外:如果你使用
print而不使用()(和raw_input()),为什么标记为python-3.x,为什么标记printf - 两个标记都是错误的。 -
一个潜在的问题是输入是
tampa(小写)还是未列出的城市。您将需要默认返回并检查城市/输入的情况