Please using code block
Computer Science
ScanSolve AI Answer
# Initialize an empty list to store the scores
scores = []
num_students = 20
print("Please enter 20 student scores:")
# Step 1: Input 20 student scores
for i in range(num_students):
while True:
try:
score = int(input(f"Enter score for student {i + 1}: "))
if 0 <= score <= 100: # Assuming scores are between 0 and 100
scores.append(score)
break
else:
print("Score must be between 0 and 100. Please try again.")
except ValueError:
print("Invalid input. Please enter an integer score.")
# Step 2: Calculate Total, Average, Highest, and Lowest scores
total_score = sum(scores)
average_score = total_score / num_students
highest_score = max(scores)
lowest_score = min(scores)
# Step 3: Display the results
print("\n--- Student Score Analysis ---")
print(f"Total number of students: {num_students}")
print(f"Total score: {total_score}")
print(f"Average score: {average_score:.2f}") # Format to 2 decimal places
print(f"Highest score: {highest_score}")
print(f"Lowest score: {lowest_score}")
Was this helpful?
Still stuck on this one?
Ask a follow-up, and the answer starts from this question.
Got a different question?Ask your own question