In: Computer Science
Next month there will a marathon. Ali, Mustafa, Ahmad, and Sami are friends and preparing for it. Each day of the week, they run a certain number of miles and write them into a notebook. At the end of the week, they would like to know the number of miles run each day, the total miles for the week, and average miles run each day.
Write a program to help them analyze their data. Your program must contain:
a function to output the results
Since the language is not provided I am doing the question in python:
Code:
read_score()- to read and store player names and miles/day.
manipulations(scores, player) : to find total miles by each of the 4 players and average of their score.
output(): to print player name and their score, the average and sum of scores.
import numpy as np
def read_store():
players=[]
score=[]
name=input("Enter name of player 1 is ")
players.append(name)
name=input("Enter name of player 2 is ")
players.append(name)
name=input("Enter name of player 3 is ")
players.append(name)
name=input("Enter name of player 4 is ")
players.append(name)
for i in range(len(players)):
score1=[]
print("Enter the score for player ", i+1)
sc=float(input("Enter score of day 1 is "))
score1.append(sc)
sc=float(input("Enter score of day 2 is "))
score1.append(sc)
sc=float(input("Enter score of day 3 is "))
score1.append(sc)
sc=float(input("Enter score of day 4 is "))
score1.append(sc)
sc=float(input("Enter score of day 5 is "))
score1.append(sc)
sc=float(input("Enter score of day 6 is "))
score1.append(sc)
sc=float(input("Enter score of day 7 is "))
score1.append(sc)
score.append(score1)
score=np.asarray(score)
players=np.asarray(players)
return players, score
def manipulations(scores,player):
for i in range(len(scores)):
print("Sum of score of", player[i], "is", np.sum(scores[i]))
print("Average of score of", player[i], "is",
np.sum(scores[i])/7)
def output():
players, scores= read_store()
for i in range(len(players)):
print(players[i],scores[i])
manipulations(scores,players)
output()
To avoid indentation errors I am attaching images:
First run read_score() and then manipulations(scores, player) and then output().
Output:
Enter name of player 1 is ALI
Enter name of player 2 is MUSTUFA
Enter name of player 3 is AHMAD
Enter name of player 4 is SAMI
Enter the score for player 1
Enter score of day 1 is 1
Enter score of day 2 is 2
Enter score of day 3 is 3
Enter score of day 4 is 4
Enter score of day 5 is 5
Enter score of day 6 is 6
Enter score of day 7 is 7
Enter the score for player 2
Enter score of day 1 is 2
Enter score of day 2 is 3
Enter score of day 3 is 4
Enter score of day 4 is 5
Enter score of day 5 is 6
Enter score of day 6 is 7
Enter score of day 7 is 8
Enter the score for player 3
Enter score of day 1 is 3
Enter score of day 2 is 4
Enter score of day 3 is 5
Enter score of day 4 is 6
Enter score of day 5 is 6
Enter score of day 6 is 7
Enter score of day 7 is 8
Enter the score for player 4
Enter score of day 1 is 9
Enter score of day 2 is 8
Enter score of day 3 is 7
Enter score of day 4 is 6
Enter score of day 5 is 4
Enter score of day 6 is 3
Enter score of day 7 is 1
ALI [1. 2. 3. 4. 5. 6. 7.]
MUSTUFA [2. 3. 4. 5. 6. 7. 8.]
AHMAD [3. 4. 5. 6. 6. 7. 8.]
SAMI [9. 8. 7. 6. 4. 3. 1.]
Sum of score of ALI is 28.0
Average of score of ALI is 4.0
Sum of score of MUSTUFA is 35.0
Average of score of MUSTUFA is 5.0
Sum of score of AHMAD is 39.0
Average of score of AHMAD is 5.571428571428571
Sum of score of SAMI is 38.0
Average of score of SAMI is 5.428571428571429
I am also attaching the image of final o/p: