Friday, 15 May 2015

Beginner of Python: when trying to import program -



Beginner of Python: <Syntaxerror: invalid syntax> when trying to import program -

this first day learning programming. i'm next python programming: introduction computer science 2nd ed. john zelle, , far things have been going smoothly.

the problem when seek , import saved programme syntaxerror. write programme , save before executing, when seek import error. tried opening fresh instance of shell no cigar. i'm using osx lion 10.8 , python 2.7.3. help appreciated. problem looks like:

>>> #file: chaos.py >>> #a simple programme illustrating chaotic behavior. >>> def main(): print "this programme illustrates chaotic function" x=input("enter number between 0 , 1: ") in range(10): x = 3.9 * x * (1-x) print x >>> main() programme illustrates chaotic function come in number between 0 , 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 phone 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

my guess copying contents of terminal file, verbatim. , there lot of thing should not there, includes version prompt.

the file should have like:

#file: chaos.py #a simple programme illustrating chaotic behavior. def main(): print "this programme illustrates chaotic function" x=input("enter number between 0 , 1: ") in range(10): x = 3.9 * x * (1-x) print x

no >>>, no ..., no tabulators , not re-create version information:

python 2.7.3 (default, dec 22 2012, 21:27:36) [gcc 4.7.2] on linux2 type "help", "copyright", "credits" or "license" more information.

python

No comments:

Post a Comment