I am having issues with my class assignment. My simple program is having a user input car speed, time traveled and tank capacity. However, when I go to calculate distance traveled (distance = input_speed * input_time) and then calculate MPG (mpg = distance / input_capacity), I am getting a divide by zero error. All of my previous inputs are listed as input_capacity = int(input("Input capacity: ")), but it is obviously not treating the number as an integer or a real number (in the case of using float for time). Can someone help me identify what I might be doing wrong or where I might need to tell the program to treat the input as a number?
Sample input and my calculation formulas below:
Bah, found my own error. I wasn't calling the functions at the end/beginning, I was calling the results.
Called the correct variable and now it works fine.
Sample input and my calculation formulas below:
def capacity_prompt():
input_capacity = 0
input_capacity = int(input("Enter the number of gallons or liters used: "))
return input_capacity
def calculate_distance(input_speed, input_time):
result_distance = 0
result_distance = input_speed * input_time
return result_distance
def calculate_mpg(result_distance, input_capacity):
result_mpg = 0
result_mpg = result_distance / input_capacity
return result_mpgBah, found my own error. I wasn't calling the functions at the end/beginning, I was calling the results.
Called the correct variable and now it works fine.
