Python 3.2.2中的打印语句中的语法错误无效
问题描述:
当我试图运行我的程序并且最后一行中的打印以红色突出显示时,出现语法错误。我不明白为什么会出现语法错误。Python 3.2.2中的打印语句中的语法错误无效
# 6. Calculate the radius of the circle using the
# distance formula on a given point and the center
r = math.sqrt((a-x)** + (b-y)**
# 7. Output to the shell the location of the center
# of the circle
print("The center of the circle is at (",x,",", y,")",sep="")
# 8. Output to the shell the radius of the circle
print("The radius of the circle is " , r)
答
r = math.sqrt((a-x)** + (b-y)**
大概应该是
r = math.sqrt((a-x)**2 + (b-y)**2)
缺少的结束括号使摊开以下系中的表达。在最后一行调用print()
之前,该表达式符合Python的语法(即使这看起来令人惊讶)。
我试着按照你的建议,但现在我得到一个无效的关闭括号的语法错误。 – Jahe234 2012-02-12 22:45:47
它做到了。非常感谢! – Jahe234 2012-02-12 22:50:18