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' % miles_traveled) Sample output with inputs: 70.0 100.0 Miles: 116.666667

Respuesta :

Answer:

Here is  code in python .

#function to calculate miles traveled

# pass two parameter in the function "miles_per_hour" and "minutes_traveled"

def mph_and_minutes_to_miles(miles_per_hour, minutes_traveled):

# convert minutes to hours

   hours_traveled = minutes_traveled / 60.0

   #calculate total miles traveled

   miles_traveled = hours_traveled * miles_per_hour

   #return the value

   return miles_traveled

#read input from user

miles_per_hour = float(input())

minutes_traveled = float(input())

#call the function and print the output

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

Explanation:

Read the value of "miles_per_hour" and "minutes_traveled" from user. call the function mph_and_minutes_to_miles() with those two parameters.calculate total hours from the minutes_traveled by dividing it with 60. then calculate the total miles by multiply hours_traveled * miles_per_hour. then return the miles travelled.

Output:

20                                                                                                                        

150                                                                                                                        

Miles: 50.000000

Simpler Codes:

The language used by computers to understand our commands and, therefore, process our requests.

The require codes are,

# mph_and_minutes_to_miles function definition

def mph_and_minutes_to_miles(miles_per_hour, minutes_travelled):

   # returning number of miles

   return (minutes_travelled/60.0)*miles_per_hour

###########################

# reading miles per hour from user

miles_per_hour = float(input())

# reading minutes travelled from user

minutes_travelled = float(input())

# printing output

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

The output is attached below:

Learn more about the topic Simpler Codes:

https://brainly.com/question/25963565

Ver imagen Omm2
ACCESS MORE