GroZnik81

account

Mar 20th, 2021
51
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Account:
  2.     balance = 0
  3.  
  4.     def __init__(self, id, name):
  5.         balance = 0
  6.         self.id = id
  7.         self.name =  name
  8.         self.balance = balance
  9.  
  10.     def credit(self,amount):
  11.         new_balance = self.balance
  12.         new_balance += amount
  13.         self.balance = new_balance
  14.         return new_balance
  15.  
  16.  
  17.     def debit(self,amount):
  18.  
  19.         if amount >= self.balance:
  20.             deb_amount = self.balance
  21.             deb_amount -= amount
  22.             return deb_amount
  23.         else:
  24.             return "Amount exceeded balance"
  25.  
  26.     def info(self):
  27.         return f"User {self.name} with account {self.id} has {self.balance} balance"
  28.  
  29.  
  30. account = Account(5411256, "Peter")
  31. print(account.debit(500))
  32. # print(account.credit(1000))
  33. # print(account.debit(500))
  34. # print(account.info())
  35.  
RAW Paste Data