这是我学习编程的第一天。我正在关注 Python Programming: An Introduction to Computer Science 2nd ed。由 John Zelle 撰写,到目前为止一切进展顺利。
唯一的麻烦是,当我尝试导入保存的程序时,我得到一个语法错误。我编写程序并在执行之前保存它,但是当我尝试导入它时,我得到了错误。我试着打开一个新的贝壳实例,但没有雪茄。我正在使用 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