[Tutor] Class instance understanding = None
David
david at abbottdavid.com
Fri Feb 27 06:06:59 CET 2009
Hi Everyone,
I go through the archived [Tutor] mail list to find programs others have
tried to do. I found one that would keep track of a petty cash fund.
please point out my misunderstanding.
Here is what I started with;
<code>
#!/usr/bin/python
from reportlab.lib.normalDate import ND
#import cPickle as p
#import pprint
today = ND()
class Account:
def __init__(self, initial):
self.balance = initial
def deposit(self, amt):
self.balance = self.balance + amt
def withdraw(self, amt):
self.balance = self.balance - amt
def getbalance(self):
return self.balance
print 'The current date is: ', today.formatUS()
data = float('100.00')
a = Account(data)
p = a.getbalance()
print 'balance = ', p
remove_data = float('50.00')
w = a.withdraw(remove_data)
print "withdraw = ", w
add_data = float('50.00')
add = a.deposit(add_data)
print "deposit = ", add
</code>
results;
The current date is: 02/27/09
balance = 100.0
withdraw = None
deposit = None
expected results;
The current date is: 02/27/09
balance = 100.0
withdraw = 50.0
deposit = 100.0
thanks,
-david
--
Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com
pgp.mit.edu
More information about the Tutor
mailing list