简体   繁体   English

Python“SyntaxError:无效语法”为什么?

[英]Python "SyntaxError: invalid syntax" why?

My formatting is terrible.我的格式很糟糕。 Screenshot is here:截图在这里:

在此处输入图片说明

n = int(input("enter the number of Fibonacci sequence you want. ")
n1 = 0
n2 = 1
count = 0

if n <= 0:
  print("please enter a postive integer")
elif n == 1:
  print("Fibonacci sequence:")
  print(n1)

else:
  while count < n:
     print(n1)
     nth = n1 + n2
     n1 = n2
     n2 = nth
     count = count + 1

I cannot figure out why do I get this error:我无法弄清楚为什么会出现此错误:

 File "<ipython-input-68-9c2ad055a726>", line 3
    n1 = 0
     ^
SyntaxError: invalid syntax

我猜第一行缺少一个 ')',这是一个问题。

When such error arises, do check for the preceding line also.当出现此类错误时,还要检查前一行。 There are very high chances of error being in the preceding line, as in this case.在前一行中出错的可能性非常高,就像在这种情况下一样。 There's a ) missing in the input line.输入行中缺少) You closed 1 ) for the input() function, but did not close for int constructor.您为 input() 函数关闭了 1 ) ,但没有为int构造函数关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM