(Analyze scores) Write a program that reads an unspecified number of scores and determines how many scores are above or equal to the average and how many scores are below the average. Assume the input numbers are separated by one space in one line.
Analyze scores Program code:
# Prompt the user to enter scores separated by spaces
marks = input("Enter scores separated by spaces: ")
# Convert the input string to a list of scores
scores = [float(score) for score in marks.split()]
# Calculate the average score
avgScore = sum(scores) / len(scores)
# Initialize counters for scores above and below the average
aboveAvgCount = 0
belowAvgCount = 0
# Count the number of scores above or equal to the average and below the average
for score in scores:
if score >= avgScore:
aboveAvgCount += 1
else:
belowAvgCount += 1
# Display the results
print("Average score:", avgScore)
print("Scores above or equal to the average:", aboveAvgCount)
print("Scores below the average:", belowAvgCount)
Executed Output:
Enter scores separated by spaces: 100 90 50 40 25 55
Average score: 60.0
Scores above or equal to the average: 2
Scores below the average: 4