Question

Q2. Ask the user for the scores of students in a class . Output the second...

Q2. Ask the user for the scores of students in a class . Output the second highest score. Sample: Enter number of students : 5 Enter scores: 10 20 50 40 90 The second highest score was 50 Note: You may assume all scores are distinct . Also for this problem you are not allowed to use the .sort() function in lists.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

n = int(input("Enter number of students : "))
scores = []

print("Enter scores: ")
for i in range(n):
scores.append(int(input()))
maxScore = scores[0]
secondMaxScore = 0
for i in range(1,n,+1):
if maxScore <= scores[i]:
secondMaxScore = maxScore
maxScore = scores[i]
elif secondMaxScore < scores[i]:
secondMaxScore = scores[i]
  
print("The second highest score was: "+str(secondMaxScore))
  

Output:

sh-4.3$ python3 main.py                                                                                                                                                                                                                                                

Enter number of students : 5                                                                                                                                                                                                                                           

Enter scores:                                                                                                                                                                                                                                                          

10                                                                                                                                                                                                                                                                     

20                                                                                                                                                                                                                                                                     

50                                                                                                                                                                                                                                                                     

40                                                                                                                                                                                                                                                                     

90                                                                                                                                                                                                                                                                     

The second highest score was: 50

ExecuteShare Code main.py x 1 n int(input (Enter number of students : )) 2 scores [] 4 print(Enter scores: ) 5 - for i in

Add a comment
Know the answer?
Add Answer to:
Q2. Ask the user for the scores of students in a class . Output the second...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program that asks user number of students in a class and their names....

    Write a C++ program that asks user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’ names and ranking. Follow the Steps Below Save the project as A4_StudentRanking_yourname....

  • In an ITEC 3150 section students have just taken a test. All the test scores are...

    In an ITEC 3150 section students have just taken a test. All the test scores are stored in an array. As the instructor you want to find what the highest score is on the test and how many students received that score. Write a method, topScore, that on an input array of integers representing students’ test scores, returns an integer array consisting of the highest score and the number of times it occurs. The following is a sample run: Input:...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

  • This program will ask the user to enter a number of players, then ask the user...

    This program will ask the user to enter a number of players, then ask the user for each player's name and score. Once all of the players have been entered, the program will display a bar chart with each of their scores scaled as a percentage of the maximum score entered. See below for details on exactly how this should work - an example transcript of how the program should work is shown below (remember that values entered by the...

  • Write a program to ask for the scores of a set of students (one at a...

    Write a program to ask for the scores of a set of students (one at a time ) and to compute and display the class average as follows: How many students? 5 What is the score for students #1? 78 What is the score for students #2? 90 What is the score for students #3?88 What is the score for students #4? 68 What is the score for students #5? 98 The class average is average ?? <= compute and...

  • Write a program that will ask the user to enter 4 quiz scores. These scores should...

    Write a program that will ask the user to enter 4 quiz scores. These scores should be from 0 to 100. Use a procedure and pass by reference to get these scores. Write a function that will find the lowest score. This score will be sent back through the function call. You still need to pass the scores by value to this function. Write a function that will calculate the average score. This value will be sent back to main...

  • Question: - write a C++ program that asks user to enter students' quiz scores, calculate the...

    Question: - write a C++ program that asks user to enter students' quiz scores, calculate the total score for each students and average for all. Note: - number of students: 1 through 5. That is, at least one student and up to 5. - number of quizes: 8 through 10. That is, at least 8 quizes and up to 10. - quiz score range: 0 through 100. - when entering quiz scores, if user enters -1, that means the user...

  • You are to write a program which will ask the user for number of students (dynamic...

    You are to write a program which will ask the user for number of students (dynamic array of class Student). For each student, you will ask for first name and number of grades (dynamic array of grades as a variable in Student). **The program should give the student random grades from 0-100** Find the averages of each student and display the information. **Display name, grades, and average neatly in a function in the Student class called Display()** Sort the students...

  • You are to write a program which will ask the user for number of students (dynamic...

    You are to write a program which will ask the user for number of students (dynamic array of class Student). For each student, you will ask for first name and number of grades (dynamic array of grades as a variable in Student). **The program should give the student random grades from 0-100** Find the averages of each student and display the information. **Display name, grades, and average neatly in a function in the Student class called Display()** Sort the students...

  • The following is data for the first and second Quiz scores for 8 students in a...

    The following is data for the first and second Quiz scores for 8 students in a class. First Quiz (Q1) Second Quiz (Q2) Plot the points in the grid below, then sketch a line that best fits the data. 8 12 16 20 24 28 31 Clear All Draw: A V O (Please Use the line above to predict the value of the second quiz score if a student had a score of 13 on the first test. enter a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT