Fibonacci numbers/program

Eric Anechiarico wedjlok at excite.com
Mon Jan 8 15:48:32 EST 2001


> Writing to a file is very easy.  You open the file for writing with
> fileobj = open(filename,"w"), then you can use its fileobj.write(s)
> method to write any string s to it -- just build the string s as you
> wish, e.g., str(anumber)+'\n' to emit the stringform of anumber
> followed by an end-of-line.
>
> As for a GUI, you have various choices, but Tkinter is probably the
> simplest toolkit to use in your case (on a Mac).  I have no Tkinter
> on Mac experience (no Mac experience at all, actually) so I'll
> refrain from any specifics, just in case there are specific issues
> I'm unaware of...
>
> Alex

Thanks for your response, Alex.  I was wondering in what context I
should use that within the program itself?  I am fairly new to Python
and have not found very many references in the books that I have read
that would show the exact sequence on when/where I would put that
string/command into effect with the code itself.

Basically, I am defining the command to
def FindFibBetween(A,B), having it go through the simple sequence of
getting the numbers, and then they output them to a screen.  I want to
interven so that it will NOT print them to a screen, but dump them
directly into a text file.

So what I need to know is at what point to I call it in the program to
open a file, write the numbers to it, and then close the file?

Here is the complete code that I use so far:

def FindFibBetween(A,B):
  x, y = 1L, 1L
  while x < B:
    if x >= A: print x
    x, y = y, x+y

then I input FindFibBetween(1, 100) or whatever range for (1, n)

Thank you for your time and assistance.

Eric


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list