In: Computer Science
In Python write a program that calculates and prints out bills of the city water company. The water rates vary, depending on whether the bill is for home use, commercial use, or industrial use. A code of r means residential use, a code of c means commercial use, and a code of i means industrial use. Any other code should be treated as an error. The water rates are computed as follows:Three types of customers and their billing rates:
Code 'r' or ‘R’ (Residential):
$5.00 plus $0.0005 per gallon used
Code 'c' or ‘C’ (Commercial):
$1000.00 for 4 million gallons or less, and $0.00025 for each additional gallon used
Code 'i' or ‘I’ (Industrial):$1000.00 if usage does not exceed 4 million gallons; $2000.00 if usage exceeds 4 million gallons
but does not exceed 10 million gallons; and $2000.00 plus $0.00025 for each additional gallon if
usage exceeds 10 million gallons.
5. For any customer, the program will display a billing summary with the following information:
a. The customer's type (Residential, Commercial, Industrial)
b. The customer's starting meter reading
c. The customer's ending meter reading
d. The total gallons of water used by the customer (end_reading – start_reading) / 10.0
e. The amount of money to be billed to the customer
All output will be appropriately labeled and formatted.
SAMPLE OUTPUT:
Here is the code:
def water_bill():
customer_type = input('Enter customer type, one from r, c, i: ')
if(customer_type != 'r' and customer_type != 'c' and customer_type != 'i'):
print('Error! Please try again.')
else:
start_reading = int(input('Enter starting meter reading: '))
end_reading = int(input('Enter ending meter reading: '))
gallon_used = (end_reading - start_reading) / 10.0
if(customer_type == 'r'):
print('\nCustomer type: Residential')
bill = 5 + (0.0005 * gallon_used)
elif(customer_type == 'c'):
print('\nCustomer type: Commercial')
if(gallon_used <= 4000000):
bill = 1000
else:
bill = 1000 + (0.00025 * (gallon_used - 4000000))
else:
print('\nCustomer type: Industrial')
if(gallon_used <= 4000000):
bill = 1000
elif(gallon_used > 4000000 and gallon_used <= 10000000):
bill = 2000
else:
bill = 2000 + (0.00025 * (gallon_used - 10000000))
print('Starting meter reading: ',start_reading)
print('Ending meter reading: ',end_reading)
print('The total gallons of water used: ',gallon_used)
print('Billed amount: ', bill)
# calling the function
water_bill()
Here is the output:
For any doubts, please comment below.