-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAll_in_One.py
More file actions
113 lines (109 loc) · 3.28 KB
/
All_in_One.py
File metadata and controls
113 lines (109 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#Here we make a bank mangment system where we cover all the topic that we cover in oop in python
class Account:
#class attribute
bank_name='HBL'
def __init__(self,name,balance):
self.name = name #instance attribute
self.__balance = balance #private attribute
#instance method show info
def show():
print(f'Name: {self.name}')
print(f'Balance: {self.__balance}')
print(f'Bank Name: {self.bank_name}')
#getter method
def get_balance(self):
return self.__balance
def withdraw(self,amount):
if self.__balance >= amount:
self.__balance -= amount
print("Withdraw successful")
else:
print("Insufficient balance")
#setter method
def set_balance(self,balance):
self.__balance = balance
def set_name(self,name):
self.name = name
#class method
@classmethod
def get_bank_name(cls):
return cls.bank_name
#static method
@staticmethod
def get_bank_address():
return "123 Main St, Karachi"
# Here we use polymorphism and inheritance
class Account:
def __init__(self,name,balance):
self.name = name
self.__balance = balance
def withdraw(self,amount):
if self.__balance >= amount:
self.__balance -= amount
print("Withdraw successful")
else:
print("Insufficient balance")
def deposit(self,amount):
self.__balance += amount
print("Deposit successful")
def get_balance(self):
return self.__balance
def get_name(self):
return self.name
def set_balance(self,balance):
self.__balance = balance
def set_name(self,name):
self.name = name
@classmethod
def get_bank_name(cls):
return cls.bank_name
@staticmethod
def get_bank_address():
return "123 Main St, Karachi"
class SavingAccount(Account):
def __init__(self,name,balance,interest_rate):
super().__init__(name,balance)
self.interest_rate = interest_rate
def withdraw(self,amount):
if self.__balance >= amount:
self.__balance -= amount
print("Withdraw successful")
else:
print("Insufficient balance")
def deposit(self,amount):
self.__balance += amount
print("Deposit successful")
def get_balance(self):
return self.__balance
def get_name(self):
return self.name
def set_balance(self,balance):
self.__balance = balance
def set_name(self,name):
self.name = name
@classmethod
def get_bank_name(cls):
return cls.bank_name
@staticmethod
def get_bank_address():
return "123 Main St, Karachi"
#creating account
account = Account("Mudassar", 1000)
account.withdraw(100)
account.deposit(100)
account.get_balance()
account.get_name()
account.set_balance(100)
account.set_name("Mudassar")
account.get_bank_name()
account.get_bank_address()
#creating saving account
saving_account = SavingAccount("Mudassar", 1000, 0.05)
saving_account.withdraw(100)
saving_account.deposit(100)
saving_account.get_balance()
saving_account.get_name()
saving_account.set_balance(100)
saving_account.set_name("Mudassar")
saving_account.get_bank_name()
saving_account.get_bank_address()