Question

In: Computer Science

In Python write a program that calculates and prints out bills of the city water company....

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:

Solutions

Expert Solution

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.


Related Solutions

Write a program that calculates and prints the bill for a cellular telephone company. The company...
Write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of services: regular and premium. Its rates vary depending on the type of service. The rates are computed as follows: Regular service: $10.00 plus the first 50 minutes are free. Charges for over 50 minutes are $0.20 per minute. Premium Service:        $25.00 plus For calls made from 6:00 A.M. to 6:00 P.M., the first 75 minutes are free; charges for over...
write a program to calculate and print payslips write program that calculates and prints payslips. User...
write a program to calculate and print payslips write program that calculates and prints payslips. User inputs are the name of employee, numbers of hours worked and hourly rate c++ language
Use Python to solve: show all work 1) Write a program that prints out a deck...
Use Python to solve: show all work 1) Write a program that prints out a deck of cards, in the format specified below. (That is, the following should be the output of your code). 2 of hearts 2 of diamonds 2 of spades 2 of clubs 3 of hearts 3 of diamonds 3 of spades 3 of clubs 4 of hearts 4 of diamonds 4 of spades 4 of clubs Continue with 5,6,7.. ending with A of hearts A of...
Write a program in PYTHON which: *Defines the following 5 functions: whoamI() This function prints out...
Write a program in PYTHON which: *Defines the following 5 functions: whoamI() This function prints out your name and PRINTS OUT any programming course you have taken prior to this course. isEven(number) This function accepts one parameter, a number, and PRINTS OUT a message telling if the numberer is even or odd. Keep in mind that a number is even if there is no remainder when the number is divided by two. printEven(number) This function accepts one parameter, a number,...
Write a pyhton program that reads a stream of bits, e.g. 11001, and calculates and prints...
Write a pyhton program that reads a stream of bits, e.g. 11001, and calculates and prints the decimal value of the binary number represented by the entered bits, i.e. 25 in this case.
Python: Write a program that plays Tic-tac-toe with a user. Each round, the game prints out...
Python: Write a program that plays Tic-tac-toe with a user. Each round, the game prints out the state of the board, asks the user where they would like to place their mark, and implements this decision. The program then places its own mark on a randomly chosen available position. Once one of the player won, the program declares the result and asks if the user would like to continue. The first player is selected at random.
You will write a monthly financial budget program in Python. INPUT: Monthly income Bills (Rent, Water...
You will write a monthly financial budget program in Python. INPUT: Monthly income Bills (Rent, Water & Electricity, Internet, Phone, Car Payment, Gas, and other expenses.) PROCESSING / CALCULATING: Current Balance (the balance left over after subtracting all the bills from the monthly income) OUTPUT: -A statement at whether the user will have money left over or not. -Amount left over. -Advice if the user has a negative balance
Write a program that prints out the characters of a string each on a line and...
Write a program that prints out the characters of a string each on a line and counts these characters.  (Do not use the length function len() ).
Write a Python program that reads in an amount in cents and prints the dollar amount...
Write a Python program that reads in an amount in cents and prints the dollar amount in that and the remaining value in cents. For example, if the amount reads in is 360 (cents), the program would print 3 dollars and 60 cents. if the amount read in is 75 (cents), the program would print 0 dollars and 75 cents.
python Write a program that prints your name 100 times to the screen. Write a function...
python Write a program that prints your name 100 times to the screen. Write a function that takes a string s and an integer n as parameters and prints the string s a total of n times (once per line). Write a for loop that prints all the integers from 3141 to 5926, skipping every other one. Write a for loop that prints every 5th integer from 5926 down to 3141. Write a program (using a for loop) to print...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT