Answer:
# Program in Python
# Take miles/gallon as input from user
miles_per_gallon = float(input('Please enter cars miles/gallon: '))
# Take dollars/gallon as input from user
dollars_per_gallon = float(input('Please enter gas dollars/gallon: '))
# Formula for calculating gas cost
dollars_per_mile = dollars_per_gallon/miles_per_gallon
# Gas cost for 20 miles
your_value1 = 20 * dollars_per_mile
# Gas cost for 75 miles
your_value2 = 75 * dollars_per_mile
# Gas cost for 500 miles
your_value3 = 500 * dollars_per_mile
# Display the results as output
print('{:.2f} {:.2f} {:.2f}'.format(your_value1, your_value2, your_value3))
Explanation:
First of all take miles/gallon and dollars/gallon as input from user and store them in their respective variables. Then calculate the gas cost by dividing dollars/gallon with miles/gallon. Multiply this calculated cost with 20, 75 and 500 respectively. Finally display the results by using print statement.
Output:
Please enter cars miles/gallon: 20.0
Please enter gas dollars/gallon: 3.1599
3.16 11.85 79.00