126k views
4 votes
LAB: Miles to track laps. (PLEASE CODE IN PYTHON)

Instructor note:
Note: this section of your textbook contains activities that you will complete for points. To ensure your work is scored, please access this page from the assignment link provided in Blackboard. If you did not access this page via Blackboard, please do so now.
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('{:.2f}'.format(your_value))
Ex: If the input is:
1.5
the output is:
6.00
Ex: If the input is:
2.2
the output is:
8.80
Your program must define and call the following function:
def miles_to_laps(user_miles)

User Harikrista
by
5.6k points

2 Answers

3 votes

Answer:

The program in python is as follows:

def miles_to_laps(user_miles):

return (user_miles/0.25)

mile = float(input("Number of Miles: "))

print("Number of laps: ",end="")

print('{:.2f}'.format(miles_to_laps(mile)))

Step-by-step explanation:

The first line defines the function miles_to_lap

def miles_to_laps(user_miles):

This line returns the equivalent number of laps

return (user_miles/0.25)

The main method starts here

This line prompts user for input

mile = float(input("Number of Miles: "))

This line prints the string "Number of laps", without the quotes

print("Number of laps: ",end="")

This prints the equivalent number of laps to two decimal places

print('{:.2f}'.format(miles_to_laps(mile)))

User Vernon
by
5.1k points
2 votes

The program converts the number of miles enters by the user to an equivalent measure in laps is written in python 3 thus :

def miles_to_laps(miles):

#initialize the function which takes in a single parameter

return (miles/0.25)

mile_value= eval(input("Number of Miles: "))

#allows user to input a value representing distance in miles

print("Number of laps: ",end="")

#display Number o laps with cursor on th same line

print('{:.2f}'.format(miles_to_laps(mile_value)))

#pass user's vlaue to the function to Obtain the lap value.

A sample run of the program is attached.

LAB: Miles to track laps. (PLEASE CODE IN PYTHON) Instructor note: Note: this section-example-1
User Cognitronic
by
5.4k points