Residential customers pay $0.004 per gallon for the first 8000 gallons. If the u
ID: 3789560 • Letter: R
Question
Residential customers pay $0.004 per gallon for the first 8000 gallons. If the usage is more than 8000 gallons, the rate will be $0.007 per gallon after the first 8000 gallons. Business customers pay $0.005 per gallon for the first 10000 gallons. If the usage is more than 10000 gallons, the rate will be $0.009 per gallon after the first 10000 gallons. For example, if a business customer has used 12000 gallons, they need to pay $50 for the first 10000 gallons ($0.005 * 100000), plus $18 for the other 2000 gallons ($0.009 * 2000). Write a program (using python) to do the following. Ask the user which type the customer it is and how many gallons of water have been used. Calculate and display the bill. The following are two examples:
Enter R for residential customer or B for business customer: b
How many gallons of water were used? 12000
Please pay this amount: 68
Enter R for residential customer or B for business customer: R
How many gallons of water were used? 9500
Please pay this amount: 42.5
Explanation / Answer
option = input("Enter R for residential customer or B for business customer:: ")
used = int(input("How many gallons of water were used? "))
rate = 0
pay = 0
if option == 'r' or option == 'R':
if used > 8000:
rate = 0.007
pay = (used - 8000) * rate
used = 8000
rate = 0.004
pay = pay + used * rate
else:
rate = 0.004
pay = used * rate
elif option=='b' or option == 'B':
if used > 10000 :
rate = 0.009
pay = (used - 10000) * rate
used = 10000
rate = 0.005
pay = pay + used * rate
else:
rate = 0.005
pay = used * rate
print("Please pay this amount: "+str(pay))
Output:
sh-4.3$ python3 main.py
Enter R for residential customer or B for business customer:: b
How many gallons of water were used? 12000
Please pay this amount: 68.0
sh-4.3$ python3 main.py
Enter R for residential customer or B for business customer:: r
How many gallons of water were used? 9500
Please pay this amount: 42.5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.