声明变量时出现语法错误

时间:2018-04-21 02:58:24

标签: python variables math

https://i.imgur.com/Rsxfuyp.png 当我运行这段代码时:

import turtle
import math
pi = math.pi
def triangle(a,b,c):
    # law of cosines, where ac = angle c
    ac = math.acos(a**2 + b**2 - c**2/(2*a*b)*180/pi
    # law of sines
    ab = math.asin(math.sin(ac)/c*b)*180/pi     
    # Angle sum theorem
    aa = 180 - (ab + ac)

    lengths = [a,b,c]
    angles = [ac,aa,ab]

    for n in range 3:
        turtle.forward(lengths[n])
        turtle.left(180-angles[n])
triangle(3,4,5)'

Sublimetext 3返回:

File "C:\Users\chul\Documents\GitHub\One-Python-Project-Per-Day\April\18 triangle.py", line 10
ab = math.asin(math.sin(ac)/c*b)*180/pi     
 ^
SyntaxError: invalid syntax

有人可以解释发生了什么吗?

1 个答案:

答案 0 :(得分:1)

你的

ac = math.acos(a**2 + b**2 - c**2/(2*a*b)*180/pi

缺少结束括号:

ac = math.acos(a**2 + b**2 - c**2/(2*a*b)*180/pi)