Question

In: Computer Science

Python problem Residential and business customers are paying different rates for water usage. Residential customers pay...

Python problem

Residential and business customers are paying different rates for water usage. Residential customers pay $0.005 per gallon for the first 6000 gallons. If the usage is more than 6000 gallons, the rate will be $0.007 per gallon after the first 6000 gallons. Business customers pay $0.006 per gallon for the first 8000 gallons. If the usage is more than 8000 gallons, the rate will be $0.008 per gallon after the first 8000 gallons. For example, a residential customer who has used 9000 gallons will pay $30 for the first 6000 gallons ($0.005 * 6000), plus $21 for the other 3000 gallons ($0.007 * 3000). The total bill will be $51. A business customer who has used 9000 gallons will pay $48 for the first 8000 gallons ($0.006 * 8000), plus $8 for the other 1000 gallons ($0.008 * 1000). The total bill will be $56. Write a program 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 some examples:

Enter R for residential customer or B for business customer: B
How many gallons of water were used? 9000
Please pay this amount: 56

Enter R for residential customer or B for business customer: R
How many gallons of water were used? 9000
Please pay this amount: 51

Please show your output in the answer, thank you!

Solutions

Expert Solution

#---------- calculator.py --------- python 3.7
#function that returns the resident pay for the given amount of gallons
def getResidentPay(gallons):
   if(gallons > 6000):
       pay = (6000 * 0.005) + ((gallons-6000) * 0.007)
   else:
       pay = gallons * 0.005
   return pay

#function that returns the business pay for the given amount of gallons
def getBusinessPay(gallons):
   if(gallons > 8000):
       pay = (8000 * 0.006) + ((gallons-8000) * 0.008)
   else:
       pay = gallons * 0.006
   return pay
#function to check valid choice is entered or not
def isValidChoice(choice):
   if(choice == "R" or choice == "B" or choice=="Q"):
       return True  
   else:
       return False
#main function to test
def main():
   choice = ""
   #till user wants to quit.
   while(choice != "Q"):
       #get choice
       choice = input("\nEnter R for residential customer or B for business customer or Q for Quit: ").strip().upper()
       #check is valid input
       if(isValidChoice(choice)):
           #if resident
           if(choice == "R"):
               try:
                   #get gallons
                   #if non numeric value is given exception will be caught and displayes
                   gallons = int(float(input("How many gallons of water were used?").strip()))
                   #if number of gallons is <=0 display error message
                   if(gallons<=0):
                       print("Invalid Number of Gallons Entered. Gallons must be > 0")
                   else:
                       #else call the resident pay
                       print("Please pay this amount: %.2f"%getResidentPay(gallons))
               except Exception:
                   print("Gallons must be a Number")
           elif(choice == "B"):
               try:
                   #if float values are entered convert them into int
                   gallons = int(float(input("How many gallons of water were used?").strip()))
                   if(gallons<=0):
                       print("Invalid Number of Gallons Entered. Gallons must be > 0")
                   else:
                       #else call the Business pay
                       print("Please pay this amount: %.2f"%getBusinessPay(gallons))
               except Exception:
                   print("Gallons must be a Number")
              
           else:
               print("Exiting...")
       else:
           print("Invalid Option Entered.")

if __name__ == "__main__":
   main()



Related Solutions

In order to estimate the average electricity usage per month, a sample of 40 residential customers...
In order to estimate the average electricity usage per month, a sample of 40 residential customers were selected, and the monthly electricity usage was determined using the customers' meter readings. Assume a population variance of 12,100kWh2. Use Excel to find the 98% confidence interval for the mean electricity usage in kilowatt hours. Round your answers to two decimal places and use ascending order. Electric Usage 765 1139 714 687 1027 1109 749 799 911 631 975 717 1232 806 637...
In order to estimate the average electricity usage per month, a sample of 125 residential customers...
In order to estimate the average electricity usage per month, a sample of 125 residential customers were selected, and the monthly electricity usage was determined using the customers' meter readings. Assume a population variance of 12,100kWh2. Use Excel to find the 98% confidence interval for the mean electricity usage in kilowatt hours. Round your answers to two decimal places and use ascending order. Electric Usage 765 1139 714 687 1027 1109 749 799 911 631 975 717 1232 806 637...
A city planner wants to estimate the average monthly residential water usage in the city. He...
A city planner wants to estimate the average monthly residential water usage in the city. He selected a random sample of 40 households from the city, which gave the mean water usage to be 3411.10 gallons over a one-month period. Based on earlier data, the population standard deviation of the monthly residential water usage in this city is 387.70 gallons. Make a 95% confidence interval for the average monthly residential water usage for all households in this city. Round your...
A retail carpet business has primarily residential customers together with a few commercial customers that make...
A retail carpet business has primarily residential customers together with a few commercial customers that make large purchases. Usually, the business sells an average of 100 square yards of carpet with a standard deviation of 90 square yards. The distribution of carpet sales is Select one: a. right-skewed. b. left-skewed. c. skewed, but we can’t tell whether it’s left-skewed or right-skewed d. approximately symmetric, but not Normal. e. approximately Normal. f. There’s no way to tell what shape the distribution...
Problem One (33%) – water usage calculation in a confined aquifer A confined aquifer with a...
Problem One (33%) – water usage calculation in a confined aquifer A confined aquifer with a storativity of 7.8 x 10-5 extends over an area of 50 km2. During the wet season the aquifer has been recharged and the storage in that area has been increased by 8 ML.      How much has the potentiometric surface raised?      If the aquifer was unconfined with a specific yield of 18%, what would be the volume recharged (in ML) for the same...
Resource Usage and Supply, Activity Rates, Service Organization EcoBrite Labs performs tests on water samples supplied...
Resource Usage and Supply, Activity Rates, Service Organization EcoBrite Labs performs tests on water samples supplied by outside companies to ensure that their waste water meets environmental standards. Customers deliver water samples to the lab and receive the lab reports via the Internet. The EcoBrite Labs facility is built and staffed to handle the processing of 100,000 tests per year. The lab facility cost $180,000 to build and is expected to last 10 years and will have no salvage value....
Resource Usage and Supply, Activity Rates, Service Organization EcoBrite Labs performs tests on water samples supplied...
Resource Usage and Supply, Activity Rates, Service Organization EcoBrite Labs performs tests on water samples supplied by outside companies to ensure that their waste water meets environmental standards. Customers deliver water samples to the lab and receive the lab reports via the Internet. The EcoBrite Labs facility is built and staffed to handle the processing of 100,000 tests per year. The lab facility cost $180,000 to build and is expected to last 10 years and will have no salvage value....
Resource Usage and Supply, Activity Rates, Service Organization EcoBrite Labs performs tests on water samples supplied...
Resource Usage and Supply, Activity Rates, Service Organization EcoBrite Labs performs tests on water samples supplied by outside companies to ensure that their waste water meets environmental standards. Customers deliver water samples to the lab and receive the lab reports via the Internet. The EcoBrite Labs facility is built and staffed to handle the processing of 100,000 tests per year. The lab facility cost $160,000 to build and is expected to last 10 years and will have no salvage value....
Scenario 1 Dubai government has stated a desire to increase recycling rates, both residential and business....
Scenario 1 Dubai government has stated a desire to increase recycling rates, both residential and business. In 2013, municipal statistics recorded as much as 2.6 million tonnes of garbage being sent to the landfill, 900,000 tonnes less than the 3.5 million tonnes sent to landfill in Dubai in 2010. However, 35 per cent of garbage is still being buried in landfills today in Dubai. Per capita, it’s estimated that Dubai residents each contribute roughly 2.7 kilos to the emirate’s waste...
In the real world of business, not all customers pay the balance they owe from purchases...
In the real world of business, not all customers pay the balance they owe from purchases they made on account. Some customers' accounts receivable become uncollectible and must be written off by the company. Explain the two methods of accounting for uncollectible accounts. Which method is required by GAAP? Explain why.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT