python 3.2.2中print语句的语法错误无效

时间:2012-02-12 22:32:08

标签: syntax python-3.x

当我尝试运行程序时出现语法错误,最后一行的打印以红色突出显示。我不明白为什么会出现语法错误。

# 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)

1 个答案:

答案 0 :(得分:2)

r = math.sqrt((a-x)** + (b-y)**

应该是

r = math.sqrt((a-x)**2 + (b-y)**2)

缺少关闭的paren使表达式扩展到以下行。直到最后一行中的print()调用,表达式符合Python的语法(即使这首先看起来令人惊讶)。

相关问题