這是我第一天學習編程。我遵循Python編程:計算機科學第二版簡介。由約翰澤爾,迄今爲止一切順利。Python初學者:<Syntaxerror:invalid syntax>試圖導入程序時
唯一的問題是,當我嘗試導入保存的程序時,出現語法錯誤。我編寫程序並在執行前保存它,但是當我嘗試導入它時,出現錯誤。我嘗試打開一個新的殼但沒有雪茄的實例。我使用的是OSX Lion 10.8和Python 2.7.3。任何幫助表示讚賞。這就是問題的樣子:
>>> #File: chaos.py
>>> #A simple program illustrating chaotic behavior.
>>> def main():
print "This program illustrates a chaotic function"
x=input("Enter a number between 0 and 1: ")
for i in range(10):
x = 3.9 * x * (1-x)
print x
>>> main()
This program illustrates a chaotic function
Enter a number between 0 and 1: .25
0.73125
0.76644140625
0.698135010439
0.82189581879
0.570894019197
0.955398748364
0.166186721954
0.540417912062
0.9686289303
0.118509010176
>>> import chaos
Traceback (most recent call last):
File "<pyshell#47>", line 1, in <module>
import chaos
File "chaos.py", line 1
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
^
SyntaxError: invalid syntax
你能張貼亂的內容。 py或至少第一行有語法錯誤? – 2013-02-17 17:31:25