SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
0.lists
Exercise:
Programming Excercises
Question:4 | ISBN:978013274719 | Edition: 6

Question

(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.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

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

 

0 0

Discussions

Post the discussion to improve the above solution.