Python Practice › OOP Programs › Program 40
Customer with deposit and withdraw
Create Customer with name and balance and methods to deposit and withdraw.
Output
750 Insufficient balance 650
Approach
- Return a message from each method.
Solution
class Customer: def __init__(self, name, balance=0): self.name, self.balance = name, balance def deposit(self, amount): self.balance += amount return self.balance def withdraw(self, amount): if amount > self.balance: return "Insufficient balance" self.balance -= amount return self.balance c = Customer("Asha", 500)print(c.deposit(250), c.withdraw(1000), c.withdraw(100))Output
750 Insufficient balance 650
Learn the concept
New to this topic? Read the lesson, then come back.