Python Practice › OOP Programs › Program 40

Customer with deposit and withdraw

EasyOOP Programs · 40 of 48

Create Customer with name and balance and methods to deposit and withdraw.

Advertisement
Output
750 Insufficient balance 650

Approach

  1. Return a message from each method.

Solution

Python
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.

More oop programs

← All 48 OOP Programs

Leave a Comment