(Find the highest score) Write a program that prompts the user to enter the number f students and each student’s score, and displays the highest score. Assume that the input is stored in a file named score.txt, and the program obtains the input from
the file.
Find the highest Score Program Code:
# Prompt the user to enter the number of students
numOfStudents = int(input("Enter the number of students: "))
# Initialize the variable for highest score
highestScore = None
# Read input from the file
with open("score.txt", "w") as file:
# Write the number of students to the file
file.write(str(numOfStudents) + "\n")
# Prompt the user to enter each student's score and write it to the file
for i in range(numOfStudents):
score = int(input("Enter the score for student {}: ".format(i+1)))
file.write(str(score) + "\n")
# Check if the current score is higher than the highest score
if highestScore is None or score > highestScore:
highestScore = score
# Display the highest score
print("The highest score is:", highestScore)
Executed Output:
Enter the number of students: 5
Enter the score for student 1: 500
Enter the score for student 2: 200
Enter the score for student 3: 900
Enter the score for student 4: 400
Enter the score for student 5: 100
The highest score is: 900
Final output data in "score.txt":
5
500
200
900
400
100