#Task1 - Set up arrays
studentNames = []
studentMarks_Test1 = []
studentMarks_Test2 = []
studentMarks_Test3 = []
eachStdTotalScore = []
student_number = 2
#input and store all names
for i in range(student_number):
print("Please key student name #", i+1)
temp_name = input("Student names-->")
studentNames.append(temp_name)
print("all students are :", studentNames)
# #input and store test1 scores
# for i in range(student_number):
# print("please key test1 score for student#",i+1)
# temp_score = int(input("score-->"))
# while True:
# try:
# if temp_score <= 20 and temp_score >= 0:
# studentMarks_Test1.append(temp_score)
# break
# raise Exception("invalid score ")
# except Exception as e:
# print('Because', e)
# temp_score = int(input("score-->"))
# print("Test 1 score= ",studentMarks_Test1)
# #input and store test2 scores
# for i in range(student_number):
# print("please key test2 score for student#",i+1)
# temp_score = int(input("score-->"))
# while True:
# try:
# if temp_score <= 25 and temp_score >= 0:
# studentMarks_Test2.append(temp_score)
# break
# raise Exception("invalid score ")
# except Exception as e:
# print('Because', e)
# temp_score = int(input("score-->"))
# print("Test 2 score= ",studentMarks_Test2)
#create function for input and store test scores
def input_score(stdNum,testNum,maxScore):
studentMarks_Temp = []
for i in range(stdNum):
print("please key test",testNum ,"score for student#",i+1)
temp_score = int(input("score-->"))
while True:
try:
if temp_score <= maxScore and temp_score >= 0:
studentMarks_Temp.append(temp_score)
break
raise Exception("invalid score ")
except Exception as e:
print('Because', e)
temp_score = int(input("score-->"))
#print("Test score= ",studentMarks_Temp)
return studentMarks_Temp
#call all functions
studentMarks_Test1 = input_score(student_number,1,20)
print("Test 1 score= ",studentMarks_Test1)
studentMarks_Test2 = input_score(student_number,2,25)
print("Test 2 score= ",studentMarks_Test2)
studentMarks_Test3 = input_score(student_number,3,35)
print("Test 1 score= ",studentMarks_Test1)
print("Test 2 score= ",studentMarks_Test2)
print("Test 3 score= ",studentMarks_Test3)
#Task 2
#Calculate total score for each student and store in the array
print("******************\nTask 2")
for i in range(student_number):
temp_StdTotalScr = stdMarks_Test1[i]+stdMarks_Test2[i]+stdMarks_Test3[i]
eachStdTotalScore.append(temp_StdTotalScr)
print(eachStdTotalScore)
#calculate average totoal score for the whole class
classTotalScr = sum(eachStdTotalScore)
avgclassTotalScr = classTotalScr/len(eachStdTotalScore)
print("Total Score for the class is:", classTotalScr)
#output each std's name followed by their total score
for i in range(student_number):
print(studentNames[i],':',eachStdTotalScore[i])
#Output the average total score for the class
print("Average Total Score for the class is:", round(avgclassTotalScr,2))
#Task 3 : Select the student with the highest total score and output their name and total score
#first find the highest score and it's index.
print("******************\nTask 3")
highestScr = max(eachStdTotalScore)
#print('highest score is :',highestScr)
highestScr_index = eachStdTotalScore.index(highestScr)
#print('the student with highest total score is at :',highestScr_index)
print(studentNames[highestScr_index], 'got the highest score of:',highestScr)
print("*********** The End ***********")
The 1D array StudentName[ ] contains the names of students in a class.
The 2D array StudentMark[ ] contains the mark for each subject, for each student.
The position of each student’s data in the two arrays is the same, for example, the student in position 10 in StudentName[ ] and StudentMark[ ] is the same.
The variable ClassSize contains the number of students in the class.
The variable SubjectNo contains the number of subjects studied.
All students study the same number of subjects.
The arrays and variables have already been set up and the data stored.
Students are awarded a grade based on their average mark