Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BankAccount():
- balance = 0
- def __init__(self, name):
- self.name = name
- def __repr__(self):
- return("Owner of account: %s. Balance: $%.2d" % (self.name, self.balance))
- def show_balance(self):
- return "Balance: %.2d" % self.balance
- def deposit(self, amount):
- if amount <= 0:
- print("Invalid amount!")
- return
- else:
- print("Depositing $%.2d" % amount)
- self.balance += amount
- self.show_balance()
- def withdraw(self, amount):
- if amount > self.balance:
- print("Invalid amount!")
- return
- else:
- print("Withdrawing $%.2d" % amount)
- self.balance -= amount
- self.show_balance()
- my_account = BankAccount("Tristan")
- print(my_account)
- print(my_account.show_balance())
- print(my_account.deposit(2000))
- print(my_account.withdraw(1000))
- print(my_account)
Add Comment
Please, Sign In to add comment