Write a program that asks for the names of three runners and the time, in minutes (no seconds, etc.), it took each of them to finish a race. The program should display the names of the runners in the order that they finished. Note, assume there are no ties.

Respuesta :

Answer:

Complete python code with explanation and output results is given below

Explanation:

User is asked to input names of runners and their finishing time

We have to determine first, second and third according to their finishing time.

if else conditioning is used to determine who has lowest finishing time.

Outer if is used to decide first position and inner if is used to decide second and third position.

str() function is used to concatenate the integer variable with string

Code:

runner1 = input("Please enter name of the runner1 ")

time1 = int(input("Please enter the time of runner1 "))

runner2 = input("Please enter name of the runner2 ")

time2 =int(input("Please Enter name of the runner2 "))

runner3 = input("Please enter name of the runner3 ")

time3 =int(input("Please Enter name of the runner3 "))

if(time1 < time2 and time1 < time3):  

   if(time2 < time3): // to decide 2nd and 3rd position

       print(runner1+" has finished First with time: "+str(time1))

       print(runner2+" has finished Second with time: "+str(time2))

       print(runner3+" has finished Third with time: "+str(time3))

   else:

       print(runner1+" has finished First with time: "+str(time1))

       print(runner3+" has finished Second with time: "+str(time3))

       print(runner2+" has finished Third with time: "+str(time2))

if(time2 < time1 and time2 < time3):  

   if(time1 < time3):

       print(runner2+" has finished First with time: "+str(time2))

       print(runner1+" has finished Second with time: "+str(time1))

       print(runner3+" has finished Third with time: "+str(time3))

   else:

       print(runner2+" has finished First with time: "+str(time2))

       print(runner3+" has finished Second with time: "+str(time3))

       print(runner1+" has finished Third with time: "+str(time1))

if(time3 < time1 and time3 < time2):

   if(time2 < time1):    

       print(runner3+" has finished First with time: "+str(time3))

       print(runner2+" has finished Second with time: "+str(time2))

       print(runner1+" has finished Third with time: "+str(time1))

   else:

       print(runner3+" has finished First with time: "+str(time3))

       print(runner1+" has finished Second with time: "+str(time1))

       print(runner2+" has finished Third with time: "+str(time2))

Output:

Program has been tested with multiple inputs and results are accurate as per problem specifications.

Please enter name of the runner1 danny

Please enter the time of runner1  45

Please enter name of the runner2  sam

Please enter the time of runner2  34

Please Enter name of the runner3  tedd

Please enter the time of runner3  23

tedd has finished First with time: 23

sam has finished Second with time: 34

danny has finished Third with time: 45

Ver imagen nafeesahmed
ACCESS MORE