[英]Python "SyntaxError: invalid syntax" why?
我的格式很糟糕。 截圖在這里:
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
我無法弄清楚為什么會出現此錯誤:
File "<ipython-input-68-9c2ad055a726>", line 3
n1 = 0
^
SyntaxError: invalid syntax
我猜第一行缺少一個 ')',這是一個問題。
當出現此類錯誤時,還要檢查前一行。 在前一行中出錯的可能性非常高,就像在這種情況下一樣。 輸入行中缺少)
。 您為 input() 函數關閉了 1 )
,但沒有為int
構造函數關閉。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.