111k views
4 votes
One lap around a standard high-school running track is exactly 0.25 miles. Write the function 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, which can be achieved as follows: print('%0.2f' % your_value)

2 Answers

3 votes

Answer:

def miles_to_laps(user_miles):

return user_miles/0.25

if __name__ == '__main__':

miles = float(input(""))

lap = miles_to_laps(miles)

print("%.2f"%lap)

Step-by-step explanation:

User Attilio
by
6.4k points
0 votes

Answer:

The solution code is written in Python 3 as the print statement stated in the question is a Python syntax.

  1. def miles_to_laps(miles):
  2. return miles / 0.25
  3. miles = 5.2
  4. num_of_lap = miles_to_laps(miles)
  5. print("Number of laps for %0.2f miles is %0.2f lap(s)" % (miles, num_of_lap))

Step-by-step explanation:

Firstly, we create a function miles_to_laps() with one parameter, miles, as required by question. The parameter miles will take a number of miles as an argument. (Line 1)

The function miles_to_laps() will operate on the value of miles by dividing it with 0.25 to return the number of lap as output. (Line 2)

After the function is ready, we can test our function. We start by creating a variable miles and assign it with a random number (e.g. 5.2) (Line 4)

Next, we call the function by passing the miles as the argument. The function shall return a lap number and assign it to the variable num_of_lap.

At last, we use the Python built-in print() function to display the number of lap in two decimal places. This can be achieved by using the placeholdher "%.2f". (Line 6). The .2 means two decimal places.

The output is as follows:

Number of laps for 5.20 miles is 20.80 lap(s)

User Eugene Lisitsky
by
6.6k points