Wrong with this script?

Daniel Fackrell unlearned at gmail.com
Sat Mar 5 15:43:46 EST 2005


"R.Meijer" <misthunter at gmail.com> wrote in message
news:baa5586e.0503051223.74bf659f at posting.google.com...
> Hi, I've been busy with an experimental script, and I can't seem to
> see what is wrong with it, can somebody tell me?
>
> Here it is:
>
> a = 0
> b = 1
> mainloop = 1
>
> print "Welcome to pyFibo"
> print "For more information type \'help\'"
> while mainloop==1:
>       limit = input("Until what number do you want to see the
> Fibonacci series?")
>       if limit=="help":
>           print "The Fibonacci series is a worldfamous series of
> numbers.\
> Each consecutive number is calculated by adding the previous two
> numbers to\
> each other."
>       else:
>           while b < limit:
>                 print b
>                 a, b = b, a+b
>           print "Want to do another series?"
>           again = input("(Type yes for another series, or anything
> else to quit.)"

You need to close the () for input here.  After doing that, if you run it
you will notice that you get an exception for most inputs, including "yes".
IIRC, input() is scheduled for removal in some future version of Python
because it doesn't do what you would expect and it is generally a bad idea
to use it.  The functionality is along the lines of:

eval(raw_input('your string here'))

You undoubtedly want raw_input() instead here.

>           if again!="yes":
>           mainloop = 0

This last line needs indented.

And a couple of minor points:

1. Choose an amount of indentation per level and stick to it.  4 is rather
common in Python code.

2. When posting to the list, make sure that the lines in your code are short
enough that they will not wrap and be posted as broken code.  70 chars is
usually safe.

Daniel Fackrell






More information about the Python-list mailing list