努力AND坚持改变 发表于 2020-2-16 16:02:22

invalid syntax 错误 谢谢鱼油们

import math
neterms = int(input("需要第几项"))
n1 = 1
n2 = 2

if neterms < 1:
    print("请输入一个大于0的数字!")
elif neterms == 1:
    print("")
elif neterms == 2:
    print("")
else:
    t=1
    count=2
    n1=1
    n2=2
    while count < neterms:
      nth = ( 1 + (math.cos(math.radians(90+90*(t-1)))**2) * n1 + ((math.sin(math.radians(90+90*(t-1)))**2))
      n1 = n2#出现错误invalid syntax
      n2 = nth
      t+=1   
      count+=1
    print(nth)               




zltzlt 发表于 2020-2-16 16:04:03

18 行少了一个右括号。应该这样:

import math
neterms = int(input("需要第几项"))
n1 = 1
n2 = 2

if neterms < 1:
    print("请输入一个大于0的数字!")
elif neterms == 1:
    print("")
elif neterms == 2:
    print("")
else:
    t=1
    count=2
    n1=1
    n2=2
    while count < neterms:
      nth = ( 1 + (math.cos(math.radians(90+90*(t-1)))**2) * n1 + ((math.sin(math.radians(90+90*(t-1)))**2)))
      n1 = n2#出现错误invalid syntax
      n2 = nth
      t+=1   
      count+=1
    print(nth)
页: [1]
查看完整版本: invalid syntax 错误 谢谢鱼油们