Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.0 kB
5
Indexable
Never
MIN_READING = 0
MAX_READING = 999999999

RESIDENTIAL_BASIC = 5.00
RESIDENTIAL_PER_GALLON = 0.0005

COMMERCIAL_BASIC = 1000.00
COMMERCIAL_CUTOFF = 4000000
COMMERCIAL_PER_GALLON = 0.00025

INDUSTRIAL_BASIC_1 = 1000.00
INDUSTRIAL_CUTOFF_1 = 4000000
INDUSTRIAL_BASIC_2 = 2000.00
INDUSTRIAL_CUTOFF_2 = 10000000
INDUSTRIAL_PER_GALLON = 0.00025

#User input
customer_code = input("Enter customer code (R, C, or I):")
#Prints invalid and exits code if user input not R, C, or I
if customer_code != "R" and customer_code != "C" and customer_code != "I":
    print('Invalid input (customer code)')

#Prompts user to input start and end reading
else:
    start_reading = int(input("Enter beginning reading (between 0 and 999999999):"))
    end_reading = int(input("Enter ending reading (between 0 and 999999999):"))
    #ends code if start and end reading outside of range [0, MAX_READING]
    if ((start_reading < MIN_READING) or (start_reading > MAX_READING)) or ((end_reading < MIN_READING) or (end_reading > MAX_READING)):
        print("Invalid input (beginning or ending reading value is out of the range)")
    #Checks if end reading is less than or equal to start reading and assigns value to used gallons
    else:
        #Initializes to_bill storing amount of money billed to costumer
        to_bill = 0
        #Assigns value to used gallons for start and end readings in range
        used_gallons = (end_reading - start_reading) / 10.0
        #Wrap-around corners situations
        if end_reading < start_reading:
            used_gallons = (MAX_READING + 1 - start_reading + end_reading) / 10.0
        
        #Computes amount money billed to costumer, based on their code and water usage; Assigns amount to to_bill
        if customer_code == "R":
            to_bill = (used_gallons * RESIDENTIAL_PER_GALLON) + RESIDENTIAL_BASIC

        if customer_code == "C":
            to_bill = COMMERCIAL_BASIC
            if used_gallons > COMMERCIAL_CUTOFF:
                to_bill += ((used_gallons - COMMERCIAL_CUTOFF) * COMMERCIAL_PER_GALLON)

        if customer_code == "I":
            if used_gallons <= INDUSTRIAL_CUTOFF_1:
                to_bill = INDUSTRIAL_BASIC_1
            elif used_gallons > INDUSTRIAL_CUTOFF_1 and used_gallons <= INDUSTRIAL_CUTOFF_2:
                to_bill = INDUSTRIAL_BASIC_2
            elif used_gallons > INDUSTRIAL_CUTOFF_2:
                to_bill = INDUSTRIAL_BASIC_2
                to_bill += ((used_gallons - INDUSTRIAL_CUTOFF_2) * INDUSTRIAL_PER_GALLON)

        #Displays customer info: Customer code, Beginning and end readings (in gallons and tenths of gallons), Gallons of water used, Amount billed 
        print("Customer code:", customer_code)

        print(f"Beginning reading value in gallons and tenths of gallon {start_reading / 10.0:.1f}")

        print(f"Ending reading value in gallons and tenths of gallon {end_reading / 10.0:.1f}")

        print(f"Gallons of water used: {used_gallons:.1f}")

        print(f"Amount billed: ${to_bill:.2f}")