-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelectricity_calc.py
41 lines (40 loc) · 1.08 KB
/
electricity_calc.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
'''
Program: WAP to input consumed unit and calculate Electricity Bill, where monthly rent Rs. 300.
Unit Charge per unit(Rs.)
Upto 300 7
301- 800 9
801-1500 12
1501 & above 15
Author: Bikramadittya Bagchi
Date: 02-02-2021
'''
# Declarations
total = 0.0
print("***Electricity bill calculator***")
# Taking input from users
while True:
try:
inp = input("Please enter the units consumed: ")
inp = int(inp)
break
except ValueError:
print("Not a valid input! Enter units in numbers only!")
if inp >= 0:
min_rent = 300
# Processing data
if inp <= 300:
if (inp * 7) < min_rent:
total = min_rent
else:
total = inp * 7
elif 300 < inp <= 800:
total = ((inp - 300) * 9) + (300 * 7)
elif 800 < inp <= 1500:
total = (300 * 7) + (500 * 9) + ((inp - 800) * 12)
else:
total = (300 * 7) + (500 * 9) + (700 * 12) + ((inp - 1500) * 15)
# Display output
print(f"Consumed unit: {inp}")
print(f"Your total bill {total}")
else:
print("Invalid unit entered!")