-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
263 lines (220 loc) · 8.49 KB
/
main.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#Program Electricity Bill with python
import string
import os
import math
totalWatt = 0
totalUnit = 0
pay = 0
day = 30
week = 4
month = 1
class Electrical_dict:
def __init__(self, name, typeDict):
self.name = name
self.typeDict = typeDict
def __repr__(self):
return str(self.name)
def printTypeList(self) :
for index, elec in enumerate(self.typeDict) :
print(f"({index}) {elec}")
print("(cancel) to stop")
class Electrical:
def __init__(self, name, watt):
self.name = name
self.watt = watt
def __repr__(self):
return str(self.name)
def getWatt(self):
print(f"{self.name} has {self.watt} watts!")
print('------------------------------------------------------')
return self.watt
electrical_list = [
Electrical_dict("Light bulb", [
Electrical("incandescent", 60),
Electrical("fluorescent", 13),
Electrical("small neon", 17),
Electrical("short neon", 28),
Electrical("long neon", 46)
]),
Electrical_dict("Fan", [
Electrical("small", 45),
Electrical("medium", 60),
Electrical("large", 75)
]),
Electrical_dict("Rice Cooker", [
Electrical("0.5L", 300),
Electrical("1L", 450),
Electrical("1.5L", 520),
Electrical("2.5L", 1100),
Electrical("4L", 1400)
]),
Electrical_dict("TV", [
Electrical("14 inch", 60),
Electrical("21 inch", 110),
Electrical("30 inch", 200)
]),
Electrical_dict("Iron", [
Electrical("normal", 1000),
Electrical("steam", 1700),
]),
Electrical_dict("Air Condition", [
Electrical("12000 BTU", 1000),
Electrical("18000 BTU", 2000),
Electrical("24000 BTU", 2500),
]),
Electrical("hot pot", 3500),
Electrical("refrigerator", 100),
Electrical("water heater", 3500),
Electrical("washing machine", 1000),
Electrical("toaster", 850),
Electrical("computer", 300),
Electrical("DVD player", 40),
Electrical("vacuum", 800),
Electrical("microwave", 1000),
Electrical("air fryer", 1200),
Electrical("electric pan", 1000)
]
def print_Electrical_List() :
for index, elec in enumerate(electrical_list) :
print(f"({index}) {elec}")
print("(cancel) to cancel all bill")
print("(cal) to calculate all bill")
def inputOk(inputt) :
try :
int(inputt)
return True
except :
return True if inputt == "cancel" or inputt == "cal" else False
def topicPrint(msg) :
print('------------------------------------')
print('************************************')
print(msg)
print('************************************')
print('------------------------------------')
def inputTopicPrint(msg) :
print('------------------------------------')
print('************************************')
keyboardInput = input(msg).lower()
print('************************************')
print('------------------------------------')
return keyboardInput
def printBill(pay) :
print("Electricity bill pay :[ %.2f ]" %pay ," Bath.")
print('------------------------------------------------------')
def printnit(totalUnit) :
print('------------------------------------------------------')
print("Total number of units you have selected is :[ %.2f ]" %totalUnit ," Unit.")
def calc_Bill(totalUnit):
if(totalUnit>0 and totalUnit<=15):
pay = totalUnit*2.3488
printnit(totalUnit)
printBill(pay)
elif(totalUnit>15 and totalUnit<=25):
pay = (15*2.3488)+(totalUnit-15)*2.9882
printnit(totalUnit)
printBill(pay)
elif(totalUnit>25 and totalUnit<=35):
pay = (15*2.3488)+((25-15)*2.9882)+(totalUnit-25)*3.2405
printnit(totalUnit)
printBill(pay)
elif(totalUnit>35 and totalUnit<=100):
pay = (15*2.3488)+((25-15)*2.9882)+((35-25)*3.2405)+(totalUnit-35)*3.6237
printnit(totalUnit)
printBill(pay)
elif(totalUnit>100 and totalUnit<=150):
pay = (15*2.3488)+((25-15)*2.9882)+((35-25)*3.2405)+((100-35)*3.6237)+(totalUnit-100)*3.7171
printnit(totalUnit)
printBill(pay)
elif(totalUnit>150 and totalUnit<=400):
pay = (15*2.3488)+((25-15)*2.9882)+((35-25)*3.2405)+((100-35)*3.6237)+((150-100)*3.7171)+(totalUnit-150)*4.2218
printnit(totalUnit)
printBill(pay)
elif(totalUnit>400):
pay =(15*2.3488)+((25-15)*2.9882)+((35-25)*3.2405)+((100-35)*3.6237)+((150-100)*3.7171)+(totalUnit-400)*4.4217
printnit(totalUnit)
printBill(pay)
else:
printBill(0)
while True :
selected = inputTopicPrint('SELECT MENU FROM FOLLOWING OPTIONS: \nChoose Electrical appliances_______(E) \nQuit_______________________________(Q) \n: ')
valid_selected = ['e','q']
if selected == 'e':
Elec = "temp"
while Elec != "cancel":
print('SELECT ELECTRICAL FROM FOLLOWING OPTIONS:\n')
print_Electrical_List()
Elec = inputTopicPrint("id : ")
while not inputOk(Elec) :
print('Valid input!')
Elec = input("id : ")
if Elec == "cancel" or Elec == "cal":
break
Elec = int(Elec)
if Elec < len(electrical_list) and Elec >= 0:
electrical = electrical_list[Elec]
watt = 0
if type(electrical) is Electrical_dict :
print('SELECT ELECTRICAL TYPE FROM FOLLOWING OPTIONS:\n')
electrical.printTypeList()
selectedType = inputTopicPrint("id : ")
while not inputOk(selectedType) :
print('Valid input!')
selectedType = input("id : ")
if selectedType == "cancel" :
continue
selectedType = int(selectedType)
typeList = electrical.typeDict
while selectedType >= len(typeList) and selectedType < 0 :
print("This number does not match any Electrical!")
selectedType = int(input("id : "))
watt = typeList[selectedType].getWatt()
elif type(electrical) is Electrical :
watt = electrical.getWatt()
else :
print("This element is not a Electrical!")
continue
time = int(input('Enter Amount of time spent : '))
freq = input('Select Frequency used by following : \n(1).Day \n(2).Week \n(3).month \n:')
if freq == '1':
allTime = time * day
elif freq == '2':
allTime = time * week
elif freq == '3':
allTime = time * month
else:
print('TRY AGAIN !!!!')
print('------------------------------------')
freq = input('Select Frequency used by following : \n(1).Day \n(2).Week \n(3).month')
unit = (watt * allTime)*0.001
print('----------------------')
print('It is [',unit,'] Unit.')
print('----------------------')
totalUnit += unit
add = input('Add more electrical : \n(Y).Yes \n(N).No \n :').lower()
print('************************************')
if add == 'y':
continue
elif add == 'n':
calc_Bill(totalUnit)
totalUnit = 0
break
else :
print('TRY AGAIN !!!!')
print('------------------------------------')
add = input('Add more electrical : \n(Y).Yes \n(N).No \n :').lower()
print('************************************')
else :
print('TRY AGAIN !!!!')
print('------------------------------------')
continue
if Elec == 'cal':
calc_Bill(totalUnit)
totalUnit = 0
elif selected == 'q':
exit()
else:
print('------------------')
print('******************')
print('RESPONSE NOT VALID')
print('******************')
print('------------------')