(Find the highest score) Write a program that prompts the user to enter the number of 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:
# Open the file in read mode
with open("score.txt", "r") as file:
# Read the number of students from the first line
numOfStudents = int(file.readline().strip())
# Initialize variable for the highest score
highestScore = -1 # Initialize to a low value
# Iterate over the scores in the file
for line in file:
# Strip leading/trailing whitespace and convert to float
score = float(line.strip())
# Check if the current score is higher than the highest score
if score > highestScore:
highestScore = score # Update the highest score
# Display the highest score
print("The highest score is:", highestScore)
Data in input file "score.txt": This file have the number of students and each student’s score.
5
100
88
66
95
75
Executed Output:
The highest score is: 100.0