On 14/03/2016 00:17, chetam.che...@gmail.com wrote:
Create a class called BankAccount
Create a constructor that takes in an integer and assigns this to a
`balance` property.
Create a method called `deposit` that takes in cash deposit amount and
updates the balance accordingly.
Create a method called `withdraw` that takes in cash withdrawal amount and updates
the balance accordingly. if amount is greater than balance return `"invalid
transaction"`
Create a subclass MinimumBalanceAccount of the BankAccount class
I've never used classes and stuff much so I gave it a go. (But I
wouldn't submit this if it's an assignment).
class ac:
balance=0
def __init__(self,openbal):
if openbal>0:
self.balance=openbal
print ("Opened account; opening balance",self.balance)
else:
print ("Invalid opening balance:",openbal)
def payin(self,amount):
if amount>0:
self.balance+=amount
print ("Paid in:",amount," New balance:",self.balance)
return 1
else:
print ("Paying in invalid sum",amount)
return 0
def takeout(self,amount):
if amount<=0:
print ("Invalid withdrawal amount",amount)
return 0
elif amount>self.balance:
print ("Not enough funds")
return 0
else:
self.balance-=amount
print ("Paid out:",amount," New balance:",self.balance)
return 1
x=ac(100)
x.payin(34)
x.takeout(70)
x.takeout(1000000)
--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list