Answer:
The solution code is written in Python 3 as the print statement stated in the question is a Python syntax.
- def miles_to_laps(miles):
- return miles / 0.25
-
- miles = 5.2
- num_of_lap = miles_to_laps(miles)
- 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)