Test Scores

Hello,
I need help writing a program that reads in 10 test scores. The test scores should be integers and should be stored in an array and they should print out the test scores in ascending order with the average. This is what I have so far:

# list() function return the elements passed as arguments as a list

# map() function applies the function pased as first argument to all elements passed after this argument

# strip() function removes the leading and trailing spaces

# split() function splits the string using space as delimeter

scores = list( map( int, input('Enter 10 test scores (seprated by space) : ').strip().split(' ') ) )

# sort the array

scores.sort()

total = 0

print('Scores : ', end = '')

# travsre the array

for x in scores:

print(x, end = ' ')



total += x



# calculate average

average = total / len(scores)

print('\nTotal Score :', total)

print('Average Score :', average)
That isn't C++.
First, posting code with code tags makes it much more readable. See https://www.cplusplus.com/articles/jEywvCM9/

Second, the things that you have written do not look like C++.
It's python.
1
2
3
4
5
6
7
8
9
10
11
12
13
scores = list( map( int, input('Enter 10 test scores (separated by space) : ').strip().split(' ') ) )
scores.sort()

total = 0

print('Scores : ', end = '')
for x in scores:
    print(x, end = ' ')
    total += x

average = total / len(scores)
print('\nTotal Score :', total)
print('Average Score :', average)



Enter 10 test scores (separated by space) : 1 2 3 4 5 5 4 3 2 1
Scores : 1 1 2 2 3 3 4 4 5 5 
Total Score : 30
Average Score : 3.0

Process finished with exit code 0
1
2
3
4
scores = [ int( s ) for s in input( 'Enter test scores: ' ).split() ]
scores.sort()
print( 'Scores: ', scores )
print( 'Average score: ', sum( scores ) / len( scores ) )



Enter test scores: 1 2 3 4 5 5 4 3 2 1
Scores:  [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]
Average score:  3.0

Last edited on
Topic archived. No new replies allowed.