-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweek 5.py
221 lines (160 loc) · 4.98 KB
/
week 5.py
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#--- OOP
# pascal case => PascalCaseVariable
class Student():
def __init__(self, name, id): # Constructor/instance method
self.name = name
self.id = id
def say_name(self):
return self.name
st1 = Student('John', '009')
st2 = Student('Mary', '007')
name = st1.say_name()
# print(name, st2.say_name())
class Order():
vendor = "Ebere Stores"
def __init__(self, quantity, price, coupon=None):
self.quantity = quantity
self.price = price
self.coupon = coupon
def get_discount(self):
if self.coupon:
return "You have a 5 percent discount"
else:
return "You have no discount"
def get_grandTotal(self):
total = self.quantity * self.price
VAT = 0.05 * total
gtotal = VAT + total
if self.coupon:
discount = 0.05 * gtotal
gtotal -= discount
return gtotal
@classmethod
def get_vendor(cls):
return cls.vendor
appleOrder = Order(5, 50, "col137")
# print(appleOrder.get_vendor())
# print(appleOrder.get_grandTotal())
# print(appleOrder.get_discount())
class Employee():
def __init__(self, id, salary, service_years):
self.id = id
self.salary = salary
self.service_years = service_years
@property
def bonus(self):
if self.service_years >= 5:
return self.salary * 0.1
else:
return "Employee not yet eligible. Thanks"
def total_salary(self):
return self.salary + self.bonus
class Manager(Employee):
def __init__(self, id, salary, service_years, branch):
super().__init__(id, salary, service_years) # represents parent class
self.branch = branch
def assign_intern(self, intern_name):
self.intern = intern_name
@property
def bonus(self):
return self.salary * 0.15
employee1 = Employee('037', 10000, 3)
# print(employee1.bonus)
manager1 = Manager('073', 15000, 5, "Victoria Island")
# print(manager1.bonus)
# print(manager1.total_salary())
#--- Task A
import random as rd
#------ creating bank object
class GreyBanking():
def __init__(self, id, name, age):
self.id = id
self.name = name
self.age = age
#--- generating account num
def create_account(self):
numbers = range(0, 10)
rd_acc = rd.sample(numbers, 10)
rd_acc = [str(item) for item in rd_acc]
acc_num = int((''.join(rd_acc)))
return acc_num
#--- handle deposits
def make_deposit(self, funds=0, deposits=[]):
deposits.append(int(funds))
self.deposit = deposits
# @property
# def all_deposits(self):
# deposits = []
# deposits.append(self.deposit)
# return deposits
@property
def total_deposits(self):
total = sum(self.deposit)
return total
#--- handle withdrawals
def make_withdrawal(self, amount=0, withdrawals=[]):
withdrawals.append(int(amount))
self.withdraw = withdrawals
# @property
# def all_withdrawals(self):
# withdrawals = []
# withdrawals.append(self.withdraw)
# return withdrawals
@property
def total_withdraws(self):
total = sum(self.withdraw)
return total
#--- handle balance
@property
def balance(self):
bal = self.total_deposits - self.total_withdraws
if bal > 0:
return bal
else:
return "Insufficient funds!!!"
# programs for bank activities
info = input(
"* Hello! To register an account, please provide;"
+ "\n" + "- A Custom ID, Full Name & Age."
+ "\n" + "- Kindly seperate each entry with a comma(',')"
+ "\n" + "Enter details here: "
)
customer = GreyBanking(info.split(',')[0], info.split(',')[1], info.split(',')[2])
accnumber = customer.create_account()
customer.make_deposit()
customer.make_withdrawal()
# bank program
def eBanking():
inputVal = int(input(
"Welcome to Grey Banking"
+ "\n" + "ENTER 1 to Get Account Details"
+ "\n" + "ENTER 2 to Make a Deposit"
+ "\n" + "ENTER 3 to Withdraw an amount"
+ "\n" + "ENTER 4 to Check Account Balance"
+ "\n" + "ENTER 0 to Exit!"
+ "\n" + "ENTER Option: "))
if inputVal == 1:
print(customer.id, customer.name, accnumber)
eBanking()
elif inputVal == 2:
customer.make_deposit(input())
print(f"Transaction Successful! Your Balance is:{customer.balance}")
eBanking()
elif inputVal == 3:
customer.make_withdrawal(input())
print(f"Transaction Successful! Your Balance is:{customer.balance}")
eBanking()
elif inputVal == 4:
print(f"Your Balance is:{customer.balance}")
eBanking()
elif inputVal == 0:
pass
#--- running program
eBanking()
# def listsum(item, summer=[]):
# summer.append(item)
# res = sum(summer)
# return res
# print(listsum(345))
# print(listsum(200))
# print(listsum(300))