Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
You are given the number of units of electricity consumed, you have to write a program to calculate the final electricity bill (in Rs) as per the following slabs.

1 - 65 units: 50 paise per unit
66 - 200 units: 65 paise per unit
201 - 475 units: Rs. 1.2 per unit
Above 475 units: Rs. 2 per unit
Additionally a surcharge of 25% is levied on the total bill. Take the number of units consumed as input from the user.



Example: U=225 units

Total bill= 65*0.5+135*0.65+25*1.2= 150.25 Rs

Final bill = 150.25 + 25% of 150.25

= 150.25 + 37.5625

= 187.8125 Rs

What I have tried:

I don't know to write finalbill as summation of total bill can anyone help me with this?

Python
U=int(input())
def TotalBill(U) :
    if (U <= 65):
        return U * 0.5
    elif (U <= 200):
        return ((65 * 0,5) + (U - 65) * 0.65)
    elif (U <= 475):
        return ((65 * 0.5) +(135 * 0.65) + (U - 200) * 1.2)
    elif (U > 475):
        return ((65 * 0.5) +(135 * 0.65) +(275 * 1.2) +(U - 475) * 2)
    else :
        return 0

print(TotalBill)
FinalBill = "TotalBill" + 0.25 * TotalBill
Posted
Updated 19-Apr-22 6:47am
v2
Comments
Richard Deeming 19-Apr-22 12:35pm    
Is your username supposed to be ironic? You clearly DON'T love studying, since you've posted at least five demands for other people to do your homework for you in the last eight hours. 🤦‍♂️

1 solution

Well, you are almost there...
Python
def TotalBill(U) :
    if (U<=0):
        return 0
    elif(U <= 65):
        return U * 0.5
    elif (U <= 200):
        return ((65 * 0,5) + (U - 65) * 0.65)
    elif (U <= 475):
        return ((65 * 0.5) +(135 * 0.65) + (U - 200) * 1.2)
    else:
        return ((65 * 0.5) +(135 * 0.65) +(275 * 1.2) +(U - 475) * 2)

U=int(input())
totalBill = TotalBill(U)
print("total bill", totalBill)
finalBill = (1.25) * totalBill
print("final bill", finalBill)
 
Share this answer
 
Comments
Patrice T 20-Apr-22 2:11am    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900