
![]() |
@wtf | |
(Simple bank account system) |
||
1
Replies
6
Views
1 Bookmarks
|
![]() |
@wtf | 8 days |
*OOP Mini Project — Bank Account System* This project ties together everything you've learned in OOP so far: - Classes & Objects - Attributes and Methods - Constructors (__init__) - Custom behaviors *Project: Simple Bank Account* We’ll create a class that mimics a real-world bank account where you can: - Deposit money - Withdraw money - Check your balance *Step-by-step Code:* class BankAccount: def __init__(self, owner, balance=0): self.owner = owner self.balance = balance def deposit(self, amount): if amount 0: self.balance += amount print(fDeposited ₹amount. New balance: ₹self.balance) else: print(Deposit amount must be positive.) def withdraw(self, amount): if 0 amount = self.balance: self.balance -= amount print(fWithdrew ₹amount. New balance: ₹self.balance) else: print(Insufficient funds or invalid amount.) def check_balance(self): print(fself.owner, your balance is ₹self.balance) *Using the Class* account1 = BankAccount(Deepak, 1000) account1.deposit(500) Deposited ₹500. New balance: ₹1500 account1.withdraw(200) Withdrew ₹200. New balance: ₹1300 account1.check_balance() Deepak, your balance is ₹1300 *What Did You Learn?* - How to manage state using attributes - How to define custom methods - Basic validation logic inside class methods - Using default arguments (balance=0) - Real-world OOP design principles |
||


