Dipu M. answered 04/03/24
Professional Java and Salesforce Mentor, Seasoned Software Engineer
def main():
num_students = int(input("Enter the number of students: "))
if num_students < 2:
print("The number of students should be at least 2.")
return
# Initialize an empty list to store student data (name and score)
students = []
# Gather data from user input
for _ in range(num_students):
name = input("Enter a student name: ")
score = float(input("Enter a student score: "))
students.append((name, score))
# Sort the list of students by score in descending order
students.sort(key=lambda student: student[1], reverse=True)
# Print the top two students
print("\nTop two students:")
print(f"{students[0][0]}'s score is {students[0][1]}")
print(f"{students[1][0]}'s score is {students[1][1]}")
if __name__ == "__main__":
main()