鱼C论坛

 找回密码
 立即注册
查看: 1429|回复: 1

[已解决]invalid syntax 错误 谢谢鱼油们

[复制链接]
发表于 2020-2-16 16:02:22 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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

if neterms < 1:
    print("请输入一个大于0的数字!")
elif neterms == 1:
    print("[1]")
elif neterms == 2:
    print("[2]")
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)               




最佳答案
2020-2-16 16:04:03
18 行少了一个右括号。应该这样:

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

  5. if neterms < 1:
  6.     print("请输入一个大于0的数字!")
  7. elif neterms == 1:
  8.     print("[1]")
  9. elif neterms == 2:
  10.     print("[2]")
  11. else:
  12.     t=1
  13.     count=2
  14.     n1=1
  15.     n2=2
  16.     while count < neterms:
  17.         nth = ( 1 + (math.cos(math.radians(90+90*(t-1)))**2) * n1 + ((math.sin(math.radians(90+90*(t-1)))**2)))
  18.         n1 = n2#出现错误invalid syntax
  19.         n2 = nth
  20.         t+=1   
  21.         count+=1
  22.     print(nth)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-2-16 16:04:03 | 显示全部楼层    本楼为最佳答案   
18 行少了一个右括号。应该这样:

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

  5. if neterms < 1:
  6.     print("请输入一个大于0的数字!")
  7. elif neterms == 1:
  8.     print("[1]")
  9. elif neterms == 2:
  10.     print("[2]")
  11. else:
  12.     t=1
  13.     count=2
  14.     n1=1
  15.     n2=2
  16.     while count < neterms:
  17.         nth = ( 1 + (math.cos(math.radians(90+90*(t-1)))**2) * n1 + ((math.sin(math.radians(90+90*(t-1)))**2)))
  18.         n1 = n2#出现错误invalid syntax
  19.         n2 = nth
  20.         t+=1   
  21.         count+=1
  22.     print(nth)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-3 18:20

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表