[Tutor] bEGINNING PROGRAMMER NEEDS HELP WITH CLASSES. CHECK CODE
Gregor Lingl
glingl@aon.at
Tue Nov 19 06:01:02 2002
Thomi Richards schrieb:
>>Pretty sure the problem lies in the def init line. Can anyone help?
>>
>>
>
>OKJ, I'm not yet very good with clases, but shouldn't it be something
>like this:
>
>
>
>
>>#Account manager program
>>from time import time, ctime
>>initial = input("Type in the initial balance of your account:")
>>
>>
>Class blah(blah blah blah)
> > def __init__(self, initial):
> > return initial
> > def deposit(initial, amt):
> > return initial + amt
> > def withdraw(initial,amt):
> > return initial - amt
> > def getbalance(initial,amt):
> > return balance
> >
>
Unfortunately this is still far from what is - presumably - desired:
class account: # (doesn't inherit from blah blah)
def __init__(self, initial):
self.balance = initial # you have to create an instance-Variable
# so the account will remember its balance
def deposit(self, amount):
self.balance += amount
....
etc.
To work successfully with classes needs certainly reading some
introductory material - I think Alan's tutor wouold be a fine starting
point:
http://www.crosswinds.net/~agauld/
Gregor
>
>etc. etc. etc.??
>
>Take a look at the classes page in teh python tutorial. It does a fairly
>good job of explaining it.
>
>
>