-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrivingCostsPython.txt
More file actions
16 lines (14 loc) · 1.74 KB
/
Copy pathDrivingCostsPython.txt
File metadata and controls
16 lines (14 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Assignment: Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 10 miles, 50 miles, and 400 miles.
Output each floating-point value with two digits after the decimal point, which can be achieved as follows:
print('{:.2f}'.format(your_value))
# define the function and set up the toal_cost equation
def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):
total_cost = (driven_miles / miles_per_gallon) * dollars_per_gallon
return total_cost
# ask user for inputs, use the driven_miles from the prompt
if __name__ == '__main__':
driven_miles = [10, 50, 400]
miles_per_gallon = float(input())
dollars_per_gallon = float(input())
for i in range(len(driven_miles)):
cost = driving_cost(driven_miles[i], miles_per_gallon, dollars_per_gallon)
print('{:.2f}'.format(cost))