[Tutor] Tutor Digest, Vol 52, Issue 66

kinuthiA muchanE muchanek at gmail.com
Tue Jun 24 19:24:31 CEST 2008


On Tue, 2008-06-24 at 15:26 +0200, tutor-request at python.org wrote:
> Message: 5
> Date: Tue, 24 Jun 2008 05:47:29 -0700 (PDT)
> From: Danny Laya <danny_laya at yahoo.com>
> Subject: [Tutor] fibonacci.py task ???
> To: tutor at python.org
> Message-ID: <635556.24859.qm at web59810.mail.ac4.yahoo.com>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> Hi all, can you explain me what this code mean :
> 
> Fibonacci.py
>   
> # This program calculates the Fibonacci sequence
> a = 0
> b = 1
> count = 0
> max_count = 20
> while count < max_count:
>     count = count + 1
>     # we need to keep track of a since we change it
>     old_a = a
>     old_b = b
>     a = old_b
>     b = old_a + old_b
>     # Notice that the , at the end of a print statement keeps it
>     # from switching to a new line
>     print old_a,
> 
> 
>  Output:
>  
> 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
> 
> Do you understand it ??? Can you explain me....ahhh.... you know
> i'm a newbie so please explain it with a simple expalanation.
> 
> And I got many tutorial with title *.py(e.g: Fibonacci.py and
> Password.py),
> can you explain me what *.py mean? Thank's for helping me.
> 
If you have an algorithm to calculate the sum of exactly two(!) numbers
you could do it in  the Python prompt by:

>>> 3+4
7


... or you could start you fire up a text editor (something like Notepad
in Windows, or nano in Linux and type "3+4"(without the quotes!),
hmmm..., and save the file as anything you want, lets say for  now you
save the file as "threePlusFour". Every time you invoke the python
interpreter (do you know how to do that?) with "threePlusFour", you will
get the value seven! 

Because there are many programming languages, such as C, java, perl,
ruby, haskell(!), you might want to be more specific as to what
programming language you save saved your code in. .c for C, .rb for
Ruby, .java for java and, of course .py for python. 

... or you could define a function...

One of the indefatigable contributors to this mailing list, Alan Gauld
(where do you get the time?), has an excellent tutorial for beginners.
Check it out at http://www.freenetpages.co.uk/hp/alan.gauld (correct?)

Kinuthia... 






More information about the Tutor mailing list