45.2k views
2 votes
Write a function so that the main program below can be replaced by the simpler code that calls function mph_and_minutes_to_miles(). Original main program: miles_per_hour = float(input()) minutes_traveled = float(input()) hours_traveled = minutes_traveled / 60.0 miles_traveled = hours_traveled * miles_per_hour print('Miles: {:f}'.format(miles_traveled))

User Sean Zhao
by
3.1k points

2 Answers

2 votes

Answer:

def mph_and_minutes_to_miles():

miles_per_hour = float(input())

minutes_traveled = float(input())

hours_traveled = minutes_traveled / 60.0

miles_traveled = hours_traveled * miles_per_hour

print('Miles: {:f}'.format(miles_traveled))

mph_and_minutes_to_miles()

Step-by-step explanation:

Create a function called mph_and_minutes_to_miles that takes no parameter

Get the code from the main part and put them inside the function

Call the function as requested

User MarkF
by
3.2k points
2 votes

Answer:

Check the explanation

Step-by-step explanation:

Solution(Simplified main code):

# Function written to simplify main code

def mph_and_minutes_to_miles(miles_per_hour, minutes_traveled):

hours_traveled = minutes_traveled / 60.0

miles_traveled = hours_traveled * miles_per_hour

return miles_traveled

miles_per_hour = float(input())

minutes_traveled = float(input())

print('Miles: %f' % mph_and_minutes_to_miles(miles_per_hour, minutes_traveled))

Kindly check the attached image below for the code screenshot and output.

Write a function so that the main program below can be replaced by the simpler code-example-1
User Rmorse
by
3.9k points