Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # A teacher needs a program to record marks for a class of 30 students who have sat three computer
- # science tests.
- # Write and test a program for the teacher.
- # - Your program must include appropriate prompts for the entry of data.
- # - Error messages and other output need to be set out clearly and understandably.
- # - All variables, constants and other identifiers must have meaningful names.
- # You will need to complete these three tasks. Each task must be fully tested.
- # TASK 1 – Set up arrays
- # Set-up one dimensional arrays to store:
- # - Student names
- # - Student marks for Test 1, Test 2 and Test 3
- # - Test 1 is out of 20 marks
- # - Test 2 is out of 25 marks
- # - Test 3 is out of 35 marks
- # Input and store the names for 30 students. You may assume that the students’ names are unique.
- # Input and store the students’ marks for Test 1, Test 2 and Test 3. All the marks must be validated on
- # entry and any invalid marks rejected.
- def avarage(array):
- return sum(array)/len(array)
- def max_value(array):
- value = None
- for i in range(len(array)):
- if i == 0:
- value = array[i]
- continue
- if array[i] > value:
- value = array[i]
- return value
- students = []
- marks_test_1 = []
- marks_test_2 = []
- marks_test_3 = []
- total_scores = []
- student_amount = 2
- for i in range(student_amount):
- student = input('Enter student name: ').title()
- mark_test_1 = None
- mark_test_2 = None
- mark_test_3 = None
- while mark_test_1 is None or mark_test_1 < 0 or mark_test_1 > 25:
- mark_test_1 = int(input('Test 1: '))
- if mark_test_1 < 0 or mark_test_1 > 25:
- while mark_test_2 is None or mark_test_2 < 0 or mark_test_2 > 30:
- mark_test_2 = int(input('Test 2: '))
- while mark_test_3 is None or mark_test_3 < 0 or mark_test_3 > 35:
- mark_test_3 = int(input('Test 3: '))
- total_score = mark_test_1 + mark_test_2 + mark_test_3
- students.append(student)
- marks_test_1.append(marks_test_1)
- marks_test_2.append(marks_test_2)
- marks_test_3.append(marks_test_3)
- total_scores.append(total_score)
- # TASK 2 – Calculate
- # Calculate the total score for each student and store in the array.
- # Calculate the average total score for the whole class.
- # Output each student’s name followed by their total score.
- # Output the average total score for the class.
- avarage_score = avarage(total_scores)
- print('\n')
- print('List of students:')
- for i in range(len(students)):
- print(f' {students[i]} [{total_scores[i]}]')
- print('----------')
- print(f'Avarage score: {avarage_score}')
- # TASK 3 – Select
- # Select the student with the highest total score and output their name and total score.
- highest_score_index = total_scores.index(max_value(total_scores))
- print(f'The highest score has: {students[highest_score_index]}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement