Home > database >  I need to make the gallons of water used 0.8 instead of 99999999.2? This is when c is inputted as th
I need to make the gallons of water used 0.8 instead of 99999999.2? This is when c is inputted as th

Time:03-12

code = input("Enter the customer's code:")
b_meter = int(input("Enter the customer's beginning meter reading:"))
e_meter = int(input("The customer's ending meter reading:"))
if e_meter > b_meter:
   used_gallons = e_meter - b_meter
else:
   used_gallons = b_meter - e_meter
if code == 'r':
   cost_gallons = float((used_gallons * 0.0005)   5)
if code == 'c':
   if used_gallons < 4000000:
       cost_gallons = 1000
   else:
       cost_gallons = (used_gallons) * 0.00025

print('Customer code:', code)
print('Beginner meter reading:', b_meter)
print('Ending meter reading:', e_meter)
print('Gallons of water used:', used_gallons / 10)
print('Amount billed:$',"{:0.2}".format(cost_gallons))

#output Enter the customer's code:c Enter the customer's beginning meter reading:999999997 The customer's ending meter reading:000000005 Customer code: c Beginner meter reading: 999999997 Ending meter reading: 5 Gallons of water used: 99999999.2 Amount billed:$ 2.5e 05

CodePudding user response:

Make the following change

if e_meter > b_meter:
    used_gallons = e_meter - b_meter
else:
    used_gallons = 1000000000 - (b_meter - e_meter)

You need to change (b_meter - e_meter) in else clause to 1000000000 - (b_meter - e_meter)

  • Related