これは私のプログラミングを学ぶ最初の日です。私はPythonプログラミングをフォローしています:コンピュータサイエンス入門第2版。ジョン・ゼレによるもので、これまでのところ順調に進んでいます。
唯一の問題は、保存したプログラムをインポートしようとすると、構文エラーが発生することです。プログラムを作成して実行する前に保存しましたが、インポートしようとするとエラーが発生します。シェルの新しいインスタンスを開いてみましたが、葉巻はありませんでした。OSXLion10.8とPython2.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