Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Why is this not working on my Driving costs - functions code

$
0
0

This is the info given for my problem:

Write a function driving_cost() with input parametersmiles_per_gallon, dollars_per_gallon, and miles_driven, that returnsthe dollar cost to drive those miles. All items are of type float.The function called with arguments (20.0, 3.1599, 50.0) returns7.89975.

Define that function in a program whose inputs are the car's miles pergallon and the price of gas in dollars per gallon (both float). Outputthe gas cost for 10 miles, 50 miles, and 400 miles, by calling yourdriving_cost() function three times.

Output each floating-point value with two digits after the decimalpoint, which can be achieved as follows: print(f'{your_value:.2f}')

Whenever I set miles_driven to float(input()) I get an EOF error and nothing happens.Maybe its just me but I have been stuck on this for a day, I can get it to print using 10,50,and 400 with 3 seperate calls but I can not get it to work with miles_driven = float

# This was the code I last tried# Define your function here.miles_per_gallon = float(input())dollars_per_gallon = float(input())miles_driven = float(input())def driving_cost(miles_per_gallon, dollars_per_gallon, miles_driven):    if miles_driven == 'None':        miles_driven = [10, 50, 400]        for m in miles_driven:            cost = (dollars_per_gallon / miles_per_gallon) * miles_driven            return cost            print(f'{cost:.2f}')    else:        cost = (dollars_per_gallon / miles_per_gallon) * miles_driven        print(f'{cost:.2f}')if __name__ == '__main__':    # Type your code here.    print(driving_cost(miles_per_gallon, dollars_per_gallon, miles_driven))

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>