Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # grades8D.py
- # ENCM 335 Fall 2019 Lab 8 Exercise D
- def print_grade_info(last_name, initials, id, score_sum, max_possible):
- name = last_name + ', ' + initials
- percent = 100.0 * score_sum / max_possible
- form = '{:<20} {:6} {:5.1f} / {:5.1f}, {:6.2f}%'
- print(form.format(name, id, score_sum, max_possible, percent))
- test_data = [
- 'Cross JP 900431 8.5 8.0 11.0 8.5 8.0 11.0 8.5 7.0 11.5 7.5',
- 'Dodd AJ 900872 8.5 8.5 10.5 9.0 -1.0 9.5 9.5 7.0 12.0 5.0',
- 'Moss WLM 901203 7.5 10.0 12.0 8.5 7.0 11.0 10.0 -1.0 13.0 -1.0',
- 'Ross T 900398 7.5 -1.0 11.0 8.5 7.0 12.0 9.0 -1.0 12.5 8.0',
- 'Todd BL 901197 9.0 8.0 -1.0 6.0 8.0 9.5 11.0 10.0 -1.0 6.0'
- ]
- max_scores = [10.0, 10.0, 12.0, 9.0, 10.0, 12.0, 11.0, 10.0, 13.0, 8.0]
- # Do not edit any of the code above this line.
- # One of the goals of this exercise is learning how to extract data items
- # from a string when the items are separated by spaces within the string.
- # The next two statements are just tests to make sure the output
- # from print_grade_info looks reasonable. Replace the statements
- # with code that will calculate and display assignment scores for
- # the students in test_data.
- i = 0
- while i < len(test_data):
- k = 3
- achieved_grade = 0
- total_grade = 105
- x = test_data[i].split()
- while k < len(x):
- if float(x[k]) > 0:
- achieved_grade += float(x[k])
- elif float(x[k]) == -1:
- total_grade -= max_scores[k-3]
- k += 1
- print_grade_info(x[0], x[1], x[2], achieved_grade, total_grade)
- i += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement