113k views
3 votes
One lap around a standard high-school running track is exactly 0.25 miles. Write the function def miles_to_laps() that takes a number of miles as an argument and returns the number of laps. Complete the program to output the number of laps. Output each floating-point value with two digits after the decimal point.

User DJ Poland
by
7.0k points

2 Answers

7 votes

Answer:

def miles_to_laps(miles):

return miles / 0.25

miles = 5.2

num_of_lap = miles_to_laps(miles)

print("%0.2f miles is %0.2f lap(s)" % (miles, num_of_lap))

Step-by-step explanation:

User Wandy
by
6.4k points
3 votes

Answer:

The python program to define a function def miles_to_laps() that takes a number of miles as an function argument and returns the number of laps is given below:

Program:

#defining the function miles_to_laps

def miles_to_laps(num_miles):

#returns the value

return num_miles/0.25

#defining the variable num_miles for user-input

num_miles=float(input("Please enter the number of miles: "))

#x1 holds the function value

x1=miles_to_laps(num_miles)

#format function is used to display the results in the given format

print("{0:.2f} miles is {1:.2f} laps".format(num_miles,x1) )

Output:

Please enter the number of miles: 7.60

7.60 miles is 30.40 laps

Step-by-step explanation:

  • Using the def keyword to define the function miles_to_laps() with function argument num_miles.
  • The function will return the number of laps(1 lap is equal to 0.25 miles).
  • The input() function will prompt the user to take the number of miles as input and store it in the variable num_miles.
  • The x1 variable holds the function value.
  • Using the format() function inside the print() function to display the result in the given format.

One lap around a standard high-school running track is exactly 0.25 miles. Write the-example-1