Question

In: Computer Science

Using LIST and FUNCTION Write a program in Python that asks for the names of three...

Using LIST and FUNCTION
Write a program in Python that asks for the names of three runners and the time it took each of them
to finish a race. The program should display who came in first, second, and third place.

Solutions

Expert Solution

Python code:

#function to print first,second and third
def first(nameList,timeList):
#checking if the first name came first
if(timeList[0]<timeList[1] and timeList[0]<timeList[2]):
#printing First person
print("First:",nameList[0])
#checking if second name is second
if(timeList[1]<timeList[2]):
#printing Second person
print("Second:",nameList[1])
#printing Third person
print("Third:",nameList[2])
else:
#printing Second person
print("Second:",nameList[2])
#printing Third person
print("Third:",nameList[1])
#checking if the second name came first
elif(timeList[1]<timeList[0] and timeList[1]<timeList[2]):
#printing First
print("First:",nameList[1])
#checking if first name is second
if(timeList[0]<timeList[2]):
#printing Second person
print("Second:",nameList[0])
#printing Third person
print("Third:",nameList[2])
else:
#printing Second person
print("Second:",nameList[2])
print("Third:",nameList[0])
#checking if the thrid name came first
elif(timeList[2]<timeList[0] and timeList[2]<timeList[1]):
#printing First
print("First:",nameList[2])
#checking if first name is second
if(timeList[0]<timeList[1]):
#printing Second person
print("Second:",nameList[0])
#printing Third person
print("Third:",nameList[1])
else:
#printing Second person
print("Second:",nameList[1])
#printing Third person
print("Third:",nameList[0])
#initializing an empty nameList
nameList=[]
#initializing an empty timeList
timeList=[]
#loop to accept names and times
for i in range(3):
#accepting name into list
nameList.append(input("Enter the name: "))
#accepting time into list
timeList.append(int(input("Enter time: ")))
#calling first function
first(nameList,timeList)


Screenshot:


Input and Output:


Related Solutions

USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
Write a program that uses Python List of strings to hold the five student names, a...
Write a program that uses Python List of strings to hold the five student names, a Python List of five characters to hold the five students’ letter grades, and a Python List of four floats to hold each student’s set of test scores. The program should allow the user to enter each student’s name and his or her four test scores. It should then calculate and display each student’s average test score and a letter grade based on the average....
Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
1. Write a python program to create a list of integers using random function. Use map...
1. Write a python program to create a list of integers using random function. Use map function to process the list on the expression: 3x2+4x+5 and store the mapped elements in another list. Now use filter to do sum of all the elements in another list. 2. Write a function that takes n as input and creates a list of n lists such that ith list contains first 10 multiples of i. 3. Write a function that takes a number...
Create this on Python Write a program that asks for three numbers. Check first to see...
Create this on Python Write a program that asks for three numbers. Check first to see that all numbers are different. If they’re not different, then exit the program. Otherwise, display the largest number of the three. Outputs: - Enter the first number: 4 - Enter the second number: 78 - Enter the third number: 8 (The largest number is 78.) Tasks - Complete the algorithm manually without using any built-in functions to find the largest number on list. -...
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
Write a Python program that calls a function to sum all the numbers in a list...
Write a Python program that calls a function to sum all the numbers in a list and returns the result to the caller. The main program creates a list (with hard-coded or user input) and passes the list as an argument to the function. You may not use the built-in function, sum. The program calls a second function to multiply all the numbers in a list passed to it by main and returns the product back to the caller. List...
Using Python Write a program that does the following in order: 1.     Asks the user to enter...
Using Python Write a program that does the following in order: 1.     Asks the user to enter a name 2.     Asks the user to enter a number “gross income” 3.     Asks the user to enter a number “state tax rate” 4.     Calculates the “Federal Tax”, “FICA tax” and “State tax” 5.     Calculates the “estimated tax” and round the value to 2 decimal places 6.     Prints values for “name”, “gross income” and “estimated tax” The program should contain three additional variables to store the Federal tax, FICA...
Write a program in python to read from a file the names and grades of a...
Write a program in python to read from a file the names and grades of a class of students to calculate the class average, the maximum, and the minimum grades. The program should then write the names and grades on a new file identifying the students who passed and the students who failed. The program should consist of the following functions: a) Develop a getGrades() function that reads data from a file and stores it and returns it as a...
(Python) a) Using the the code below write a function that takes the list xs as...
(Python) a) Using the the code below write a function that takes the list xs as input, divides it into nss = ns/nrs chunks (where nrs is an integer input parameter), computes the mean and standard deviation s (square root of the variance) of the numbers in each chunk and saves them in two lists of length nss and return these upon finishing. Hint: list slicing capabilities can be useful in implementing this function. from random import random as rnd...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT