【发布时间】:2016-05-07 00:13:06
【问题描述】:
这是我的代码:
def trip(nights):
return 140 * nights
def plane_cost(ride):
if ride == "London":
return 220
elif ride == "Rome":
return 200
elif ride == "Glascow":
return 185
def car_rental(days):
cost = 20 * days
if days >= 7:
cost = cost - 25
if days >= 3:
cost = cost - 10
return cost
def tripcost(ride, days, spending_pounds):
trip(days) + plane_cost(ride) + car_rental(days) + spending_pounds
print tripcost("London", 5, 500)
想知道为什么当我在 idlE 中加载单词 tripcost(以粗体标记)时显示为语法错误?
【问题讨论】:
-
我打赌 TextWrangler 是 Python 2 并且您的 IDE 连接到 Python 3 的安装。是这样吗?尝试将最后一行更改为
print(tripcost("London", 5, 500))。 -
@JRazor - 我认为 OP 只是用星号指出错误所在。问题中没有其他任何迹象表明需要粗体文本。
-
请edit您的帖子并添加语法错误的全文。
-
除非 IDE 做一些额外的事情,而 IDLE 没有,SyntaxErrors 来自 python x.y 解析器/编译器。同样,使用的编辑器是无关紧要的,除非它改变了你输入的内容,而 IDLE 也不会。如果报告准确,这一定是 2 对 3 语法更改问题。
标签: python python-2.7 python-3.x textwrangler