In: Computer Science
Write a beginner's program in Python to determine your car's gas mileage. You should use the input variables "miles_traveled" and "gallons_fuel" and the result should be stored in the variable "miles_per_gallon".
Solution for the given question are as follows -
Code :
# get inputs from user
print('Enter Total Miles Traveled : ')
total_miles_traveled = int(input())
print('Enter Current Miles Traveled : ')
miles_traveled = int(input())
print('Enter Gallons Fuel : ')
gallons_fuel = int(input())
# calculate miles_per_gallon
miles_per_gallon = (total_miles_traveled - miles_traveled) /
gallons_fuel
# print the result
print("Miles per Gallons : ", miles_per_gallon)
Code Screen Shot :
Output :