Jul-17-2019, 01:43 PM
I was to create a program so I can compare the cost of fuel per vehicle I was wanting to purchase. I was able to get it to work but I think it can be simplified, maybe to clunky
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# introductory statement intro = ''' Automobile Fuel Cost Calculator This program may help you decide which car makes sense for you based on your budget. You will be asked to enter the MPG for the car you have in mind, the average number of miles you expect to drive each month and the cost per gallon for the fuel. ''' print (intro) # user adds miles per gallon mpg = input ( "Please enter mpg (miles per gallon:" ) mpg = float (mpg) # user enters miles for the month distance = input ( "Please enter the average miles driven in a month:" ) distance = float (distance) # user enters price per gallon ppg = input ( "Enter fuel price per gallons:" ) ppg = float (ppg) a = distance b = ppg c = mpg total1 = a / c total2 = b * total1 print ( "Given that the price of fuel is at ${:.2f}/gallon and you travel around {} miles per month:" . format (ppg, distance)) print ( "Amount of gallons in fuel used each month is: {0:.1f}" . format (total1)) print ( "Your monthly estimated cost of fuel is: ${0:.2f}" . format (total2)) |