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 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.
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 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...
Python # Write a program that examines three variables—x, y, and z # and prints the...
Python # Write a program that examines three variables—x, y, and z # and prints the largest odd number among them. # If none of them are odd, it should print a message to that effect. n = input('Enter the 1st Integer x: ') x = int(n) n = input('Enter the 2nd Integer y: ') y = int(n) n = input('Enter the 3rd Integer z: ') z = int(n) if x % 2 == 0 and y % 2 ==...
Python Assume s is a string of numbers. Write a program that prints the longest substring...
Python Assume s is a string of numbers. Write a program that prints the longest substring of s in which the numbers occur in ascending order and compute the average of the numbers found. For example, if s = '561984235272145785310', then your program should print: Longest substring in numeric ascending order is: 14578 Average: 5 In the case of ties, print the first substring. For example, if s = '147279', then your program should print Longest substring in numeric ascending...
Text Wrap Problem Write a program in Python that takes an input string and prints it...
Text Wrap Problem Write a program in Python that takes an input string and prints it as multiple lines of text such that no line of text is greater than 13 characters and words are kept whole. For example, the first line of the Gettysburg address: Four score and seven years ago our fathers brought forth upon this continent a new nation, conceived in liberty and dedicated to the proposition that all men are created equal Becomes: Four score and...
Write a program which prompts the user for a positive integer, and then prints out the...
Write a program which prompts the user for a positive integer, and then prints out the prime factorization of their response. Do not import anything other than the Scanner. One way you might go about this using nested loops: Start a "factor" variable at 2 In a loop: repeatedly print the current factor, and divide the user input by it, until the user input is no longer divisible by the factor increment the factor This plan is by no stretch...
Write a program that asks the user for an integer and then prints out all its...
Write a program that asks the user for an integer and then prints out all its factors. For example, when the user enters 84, the program should print 2 2 3 7 Validate the input to make sure that it is not a character or a string using do loop.in c++
Python Write a program that takes a text filename as command line argument, and prints number...
Python Write a program that takes a text filename as command line argument, and prints number of times each letter occurred in this file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT