Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. # A teacher needs a program to record marks for a class of 30 students who have sat three computer
  2. # science tests.
  3.  
  4. # Write and test a program for the teacher.
  5. # - Your program must include appropriate prompts for the entry of data.
  6. # - Error messages and other output need to be set out clearly and understandably.
  7. # - All variables, constants and other identifiers must have meaningful names.
  8.  
  9. # You will need to complete these three tasks. Each task must be fully tested.
  10.  
  11.  
  12. # TASK 1 – Set up arrays
  13.  
  14. # Set-up one dimensional arrays to store:
  15. # - Student names
  16. # - Student marks for Test 1, Test 2 and Test 3
  17. # - Test 1 is out of 20 marks
  18. # - Test 2 is out of 25 marks
  19. # - Test 3 is out of 35 marks
  20.  
  21. # Input and store the names for 30 students. You may assume that the students’ names are unique.
  22.  
  23. # Input and store the students’ marks for Test 1, Test 2 and Test 3. All the marks must be validated on
  24. # entry and any invalid marks rejected.
  25.  
  26. def avarage(array):
  27. return sum(array)/len(array)
  28.  
  29.  
  30. def max_value(array):
  31. value = None
  32. for i in range(len(array)):
  33. if i == 0:
  34. value = array[i]
  35. continue
  36.  
  37. if array[i] > value:
  38. value = array[i]
  39.  
  40. return value
  41.  
  42.  
  43. students = []
  44. marks_test_1 = []
  45. marks_test_2 = []
  46. marks_test_3 = []
  47. total_scores = []
  48. student_amount = 2
  49.  
  50. for i in range(student_amount):
  51. student = input('Enter student name: ').title()
  52. mark_test_1 = None
  53. mark_test_2 = None
  54. mark_test_3 = None
  55.  
  56. while mark_test_1 is None or mark_test_1 < 0 or mark_test_1 > 25:
  57. mark_test_1 = int(input('Test 1: '))
  58. if mark_test_1 < 0 or mark_test_1 > 25:
  59.  
  60.  
  61. while mark_test_2 is None or mark_test_2 < 0 or mark_test_2 > 30:
  62. mark_test_2 = int(input('Test 2: '))
  63.  
  64. while mark_test_3 is None or mark_test_3 < 0 or mark_test_3 > 35:
  65. mark_test_3 = int(input('Test 3: '))
  66.  
  67. total_score = mark_test_1 + mark_test_2 + mark_test_3
  68.  
  69. students.append(student)
  70. marks_test_1.append(marks_test_1)
  71. marks_test_2.append(marks_test_2)
  72. marks_test_3.append(marks_test_3)
  73. total_scores.append(total_score)
  74.  
  75. # TASK 2 – Calculate
  76.  
  77. # Calculate the total score for each student and store in the array.
  78. # Calculate the average total score for the whole class.
  79.  
  80. # Output each student’s name followed by their total score.
  81. # Output the average total score for the class.
  82.  
  83. avarage_score = avarage(total_scores)
  84.  
  85. print('\n')
  86. print('List of students:')
  87. for i in range(len(students)):
  88. print(f' {students[i]} [{total_scores[i]}]')
  89.  
  90. print('----------')
  91. print(f'Avarage score: {avarage_score}')
  92.  
  93.  
  94. # TASK 3 – Select
  95. # Select the student with the highest total score and output their name and total score.
  96.  
  97. highest_score_index = total_scores.index(max_value(total_scores))
  98. print(f'The highest score has: {students[highest_score_index]}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement