|
| 1 | +# TODO: |
| 2 | +# Parent Class : User |
| 3 | +# Holds details about an user |
| 4 | +# Has function to show user details |
| 5 | +# Child Class : Bank |
| 6 | +# Stores details about the account balance |
| 7 | +# Stores details about the amount |
| 8 | +# Allows for deposit, withdraw and view balance |
| 9 | + |
| 10 | +# Parent Class |
| 11 | +class User(): |
| 12 | + def __init__(self,name,age,gender): |
| 13 | + self.name = name |
| 14 | + self.age = age |
| 15 | + self.gender = gender |
| 16 | + |
| 17 | + def show_details(self): |
| 18 | + print(f""" |
| 19 | + Personal Details |
| 20 | + ------------------------- |
| 21 | + Name : {self.name} |
| 22 | + Age : {self.age} |
| 23 | + Gender : {self.gender} |
| 24 | + """) |
| 25 | + |
| 26 | +# arjun = User('Arjun',20,'Male') |
| 27 | +# print(arjun) |
| 28 | +# arjun.show_details() |
| 29 | + |
| 30 | +# Child Class |
| 31 | +class Bank(User): |
| 32 | + def __init__(self, name, age, gender): |
| 33 | + super().__init__(name, age, gender) |
| 34 | + self.balance = 0 |
| 35 | + |
| 36 | + def deposit(self,amount): |
| 37 | + self.amount = amount |
| 38 | + self.balance += self.amount |
| 39 | + print(f"Successfully Deposited : ${self.amount}") |
| 40 | + print(f"Current Balance : ${self.balance}") |
| 41 | + print() |
| 42 | + |
| 43 | + def withdraw(self,amount): |
| 44 | + self.amount = amount |
| 45 | + if self.amount < self.balance: |
| 46 | + self.balance -= self.amount |
| 47 | + print(f"Successfully Withdrawn ${self.amount}") |
| 48 | + print(f"Current Balance : ${self.balance}") |
| 49 | + print() |
| 50 | + else: |
| 51 | + print("Not Enough Balance!!!") |
| 52 | + print(f"Current Balance : ${self.balance}") |
| 53 | + print() |
| 54 | + |
| 55 | + def view_balance(self): |
| 56 | + self.show_details() |
| 57 | + print(" -------------------------") |
| 58 | + print(f" Current Balance : ${self.balance}") |
| 59 | + print() |
| 60 | + |
| 61 | +#-------------------------------------------------- |
| 62 | + |
| 63 | +sbi = Bank('Akshay',20,'Male') |
| 64 | +print(sbi) |
| 65 | +# sbi.show_details() |
| 66 | +# sbi.view_balance() |
| 67 | +# sbi.deposit(100) |
| 68 | +sbi.deposit(1000) |
| 69 | +sbi.withdraw(100) |
| 70 | +# sbi.withdraw(1100) |
0 commit comments