Advertisement
RedoGaming

basic bank account in python

Apr 30th, 2025 (edited)
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | Source Code | 0 0
  1. class bank:
  2.     def __init__(self, balance, owner):
  3.        
  4.         self.balance = balance
  5.         self.owner = owner
  6.        
  7.     def withdraw(self):
  8.         amt = int(input(self.owner + ", how much would you like to withdraw?\n"))
  9.         if amt < self.balance or amt == self.balance:
  10.             print("You have successfully withdrawn", amt, "dollars!")
  11.             self.balance = self.balance - amt
  12.             print("You now have", self.balance, "dollars")
  13.         elif amt > self.balance:
  14.             print("You do not have enough money for this transaction!")
  15.    
  16.     def deposit(self):
  17.         amt = int(input(self.owner + ", how much would you like to deposit?\n"))
  18.         self.balance = self.balance + amt
  19.         print("You now have", self.balance, "dollars!")
  20.    
  21.     def check_bal(self):
  22.         return self.balance
  23.  
  24.  
  25. myacc = bank(100, "Redo")
  26.  
  27. while True:
  28.     area = input("\nWhat would you like to do? [Check Balance] [Deposit] [Withdraw] [Exit]\n")
  29.    
  30.     if area.lower() == "check balance":
  31.         print("You have", myacc.check_bal(), "dollars!")
  32.     elif area.lower() == "deposit":
  33.         myacc.deposit()
  34.     elif area.lower() == "withdraw":
  35.         myacc.withdraw()
  36.     elif area.lower() == "exit":
  37.         print("Exiting. Goodbye!")
  38.         break
  39.     else:
  40.         print("Invalid option. Try again.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement