Though it seems easy to answer this question, but I really struggled. Please hel
ID: 3809523 • Letter: T
Question
Though it seems easy to answer this question, but I really struggled. Please help! Python using loops
Find the two highest scores. Write a program that prompts the user to enter the number of students and each student's score, and displays the highest and the second highest scores.
my struggle was to find the second highest score using this code:
numofstudents = eval(input("Enter the number of students: "))
student1 = input("Enter a student name: ")
score1 = eval(input("Enter a student score: "))
for i in range(numofstudents - 1):
student = input("Enter a student name: ")
score = eval(input("Enter a student score: "))
if score > score1:
student1 = student
score1 = score
print("The highest score", student,"'s score is ", score)
# there is should be a few changes to find the second highest score in this code.
Explanation / Answer
numofstudents = eval(input("Enter the number of students:
"))
student1 = input("Enter a student name: ")
score1 = eval(input("Enter a student score: "))
score2 = score1
for i in range(numofstudents - 1):
student = input("Enter a student name: ")
score = eval(input("Enter a student score: "))
if score > score1:
student1 = student
score1 = score
else if score > score1 && score!= score1
score2 = score
print("The highest score", student,"'s score is ", score)
print("The Second highest score", student,"'s score is ", score2)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.