object - oriented programming Help!!

Rikard Bosnjakovic bos at hack.org
Tue Jul 3 08:41:23 EDT 2001


eric_brake wrote:
> 
> What am I doing wrong? I am trying to learn object oriented
> programming, but I don't know what I'm doing wrong.

You try to make an instance before you define the class and you can't
use "self" when initializing it. Change your code to this one:

class fibonaccii:
    def fib(self, fibnumber):
        a, b = 0, 1
        while b < fibnumber:
            print b,
            a, b = b, a+b

fibinstance = fibonaccii() #create instance


>>> ## working on region in file /usr/tmp/python-918a2M...
>>> fibinstance.fib(7)
1 1 2 3 5

-- 
Rikard Bosnjakovic - http://bos.hack.org/cv/ - ICQ: 1158217

Anyone sending unwanted advertising e-mail to my address will be
charged $250 for network traffic and computing time. By extracting my
address from this message or its header, you agree to these terms.



More information about the Python-list mailing list