|
Post by rajeshmenon on Mar 23, 2020 20:26:52 GMT -5
Water Charges
0000 to 1200 CF $2.788 per 100 Cubic Feet 1201 to 3600 CF $5.017 per 100 Cubic Feet 3601 to + CF $5.574 per 100 Cubic Feet
If my water meter shows 28000 Gallons for this month, How much will my water bill be ?
|
|
|
Post by eastwood on Mar 24, 2020 21:08:01 GMT -5
I got the answer 104.34968587087288
|
|
|
Post by pkbalan2010 on Mar 24, 2020 23:48:36 GMT -5
I got the answer as: 161.83861032 Total Charges for ( 28000 Gallon OR 3743.068 CF) is ( 33.455999999999996 + 120.40800000000002 + 7.974610319999986 )= 161.83861032
Here is the code
# 0000 to 1200 CF $2.788 per 100 Cubic Feet
# 1201 to 3600 CF $5.017 per 100 Cubic Feet
# 3601 to + CF $5.574 per 100 Cubic Feet
GallonToCF = 0.133681
Slab1 = 1200
Slab2 = 3600
Slab1Rate = 2.788
Slab2Rate = 5.017
Slab3Rate = 5.574
WaterUsedInGl = input ("Enter Water used (in Gallons): ")
WaterUsedInCF = int(WaterUsedInGl) * GallonToCF
if WaterUsedInCF <= Slab1 :
Price = float(WaterUsedInCF * Slab1Rate)/100
elif int(WaterUsedInCF) <= Slab2 :
Price = float(Slab1 * Slab1Rate)/100 + float((WaterUsedInCF - Slab1) * Slab2Rate)/100
else :
Price = float(Slab1 * Slab1Rate)/100 + float((Slab2 - Slab1) * Slab2Rate)/100 + float((WaterUsedInCF - Slab2) * Slab3Rate)/100
print ("Total Charges for (", int(WaterUsedInGl),"Gallon OR ", round(WaterUsedInCF,4),"CF) is ( ", float(Slab1 * Slab1Rate)/100, "+",float((Slab2 - Slab1) * Slab2Rate)/100, "+", float((WaterUsedInCF - Slab2) * Slab3Rate)/100,")=", Price)
|
|
|
Post by deepak on Mar 25, 2020 16:57:31 GMT -5
reading = input("Enter the water usage in gallons: ")
bill = 0 number_gallons = int(reading)
if (number_gallons < 1201): bill = number_gallons * 2.788 elif (number_gallons < 3601): bill = number_gallons * 5.017 else: bill = number_gallons * 5.574 print("Water bill = $" + str(bill))
==================================== Results: Enter the water usage in gallons: 2800 Water bill = $14047.6
|
|
|
Post by deepak on Mar 25, 2020 17:01:18 GMT -5
Correction: the charge was for per 100cf (hence need to divide by 100)
Enter the water usage in gallons: 2800 Water bill = $140.476
|
|
|
Post by rajeshmenon on Mar 25, 2020 18:02:59 GMT -5
I got the answer 104.34968587087288 Incorrect answer. Please share your code
|
|
|
Post by rajeshmenon on Mar 25, 2020 18:03:38 GMT -5
I got the answer as: 161.83861032 Total Charges for ( 28000 Gallon OR 3743.068 CF) is ( 33.455999999999996 + 120.40800000000002 + 7.974610319999986 )= 161.83861032 The answer is correct, please share your code.
|
|
|
Post by rajeshmenon on Mar 25, 2020 18:05:10 GMT -5
reading = input("Enter the water usage in gallons: ") bill = 0 number_gallons = int(reading) if (number_gallons < 1201): bill = number_gallons * 2.788 elif (number_gallons < 3601): bill = number_gallons * 5.017 else: bill = number_gallons * 5.574 print("Water bill = $" + str(bill)) ==================================== Results: Enter the water usage in gallons: 2800 Water bill = $14047.6 Incorrect answer Deepak. you need to convert the gallons to cu feet and a few more things. Good effort, needs a few more steps.
|
|
|
Post by mayilsrinivasan on Mar 25, 2020 18:48:43 GMT -5
mR=28000
meter_reading= mR* 0.133681
total_bill_amt=0
if(meter_reading<1200):
total_bill_amt=2.788*meter_reading
elif(meter_reading>1201 and meter_reading<3601):
total_bill_amt=(1200 * 2.788 )+5.017*(meter_reading-1200)
else:
total_bill_amt=(1200 * 2.788 )+5.017*2400 + 5.574*(meter_reading-3600)
print("Total charges",total_bill_amt/100) Ans: 161.83
|
|
|
Post by pkbalan2010 on Mar 25, 2020 18:49:41 GMT -5
Here is the code ------------------------
# 0000 to 1200 CF $2.788 per 100 Cubic Feet
# 1201 to 3600 CF $5.017 per 100 Cubic Feet
# 3601 to + CF $5.574 per 100 Cubic Feet
GallonToCF = 0.133681
Slab1 = 1200
Slab2 = 3600
Slab1Rate = 2.788
Slab2Rate = 5.017
Slab3Rate = 5.574
WaterUsedInGl = input ("Enter Water used (in Gallons): ")
WaterUsedInCF = int(WaterUsedInGl) * GallonToCF
if WaterUsedInCF <= Slab1 :
Price = float(WaterUsedInCF * Slab1Rate)/100
elif int(WaterUsedInCF) <= Slab2 :
Price = float(Slab1 * Slab1Rate)/100 + float((WaterUsedInCF - Slab1) * Slab2Rate)/100
else :
Price = float(Slab1 * Slab1Rate)/100 + float((Slab2 - Slab1) * Slab2Rate)/100 + float((WaterUsedInCF - Slab2) * Slab3Rate)/100
print ("Total Charges for (", int(WaterUsedInGl),"Gallon OR ", round(WaterUsedInCF,4),"CF) is ( ", float(Slab1 * Slab1Rate)/100, "+",float((Slab2 - Slab1) * Slab2Rate)/100, "+", float((WaterUsedInCF - Slab2) * Slab3Rate)/100,")=", Price)
Answer: 161.83861032
Enter Water used (in Gallons): 28000
Total Charges for ( 28000 Gallon OR 3743.068 CF) is ( 33.455999999999996 + 120.40800000000002 + 7.974610319999986 )= 161.83861032
|
|
|
Post by deepak on Mar 25, 2020 18:52:55 GMT -5
Ahh.. I didn't pay attention to converting from gallons to cubic feet (1 gallon = 0.133681 cf)
Here's another attempt:
reading = input("Enter the water usage in gallons: ")
bill = 0 number_gallons = int(reading) cubic_feet = number_gallons * 0.133681 print(cubic_feet)
bill = cubic_feet * 2.788
if (cubic_feet > 1200): cubic_feet -= 1200 bill += cubic_feet * (5.017 - 2.788) if (cubic_feet > 2400): cubic_feet -= 2400 bill += cubic_feet * (5.574 - 5.017)
bill = bill / 100 print("Water bill = $" + str(bill))
============================================ Result: Enter the water usage in gallons: 28000 3743.0679999999998 Water bill = $161.83861032
|
|
|
Post by poorna on Mar 25, 2020 19:56:41 GMT -5
consumption_gallons = eval(input('Enter consumption: '))
consumption_incf = consumption_gallons * 0.133681
if consumption_incf < 1200:
Water_bill = (consumption_incf/100 * 2.788)
elif 1201<consumption_incf<3600:
Water_bill= (consumption_incf/100 * 5.017)
elif consumption_incf >=3601:
Water_bill = (consumption_incf/100 * 5.574)
Water_bill = round(Water_bill, 2)
print('Water bill is '+ str(Water_bill) + ' dollars')
Enter consumption: 28000
Water bill is 208.64 dollars
|
|
|
Post by rajeshmenon on Mar 26, 2020 11:53:59 GMT -5
consumption_gallons = eval(input('Enter consumption: ')) consumption_incf = consumption_gallons * 0.133681 if consumption_incf < 1200: Water_bill = (consumption_incf/100 * 2.788) elif 1201<consumption_incf<3600: Water_bill= (consumption_incf/100 * 5.017) elif consumption_incf >=3601: Water_bill = (consumption_incf/100 * 5.574) Water_bill = round(Water_bill, 2) print('Water bill is '+ str(Water_bill) + ' dollars') Enter consumption: 28000 Water bill is 208.64 dollars Sorry Poorna you answer was incorrect. Very good attempt, but one thing that you missed was the slabs of water charges. Between the first range its a different price, same with the second slab and so on, so only the excess beyond 3600 will be charged at that rate. The problem is not simple as it looks. so between 0 to 1200 - it will be 12 * 2.788 - waterbill1 1201 to 2600 - it will be 24 * 5.017 - waterbill2 above 3600 will be waterbill1 + waterbill2 + excess *5.574
I hope its clear, if not do let me know i will try to explain more.
|
|
|
Post by jeerav on Mar 29, 2020 12:01:41 GMT -5
Thanks for the exercise. My answer is $ 161.83861032
Jeevan Ravindran
Please see the code below:
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sun Mar 29 11:20:26 2020
@author: JKR
Water Charges
0000 to 1200 CF $2.788 per 100 Cubic Feet 1201 to 3600 CF $5.017 per 100 Cubic Feet 3601 to + CF $5.574 per 100 Cubic Feet
If my water meter shows 28000 Gallons for this month, How much will my water bill be ?
'1 Cubic foot (ft3) is equal to 7.48051948 gallons
"""
meter_gal = float(input("Enter your meter reading in Gallons: "))
Upper1 = 1200 rate1 = 2.788 Upper2 = 3600 rate2 = 5.017 rate3 = 5.574
#Convert input gallons to cubic feet by multiplying 0.133681 meter_CF = float( meter_gal * 0.133681 )
#define and initialize Charge Charge = float(0)
if meter_CF <= Upper1: Charge = (meter_CF * rate1) / 100 elif meter_CF > Upper1 and meter_CF <= Upper2: Charge = ( Upper1 * rate1 + (meter_CF - Upper1) * rate2 ) / 100 else: Charge = ( Upper1 * rate1 + (Upper2 - Upper1) * rate2 + (meter_CF - Upper2) * rate3 ) / 100 print("Your charge for ", meter_gal, "gallons is $", Charge )
|
|