Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. # grades8D.py
  2. # ENCM 335 Fall 2019 Lab 8 Exercise D
  3.  
  4. def print_grade_info(last_name, initials, id, score_sum, max_possible):
  5.     name = last_name + ', ' + initials
  6.     percent = 100.0 * score_sum / max_possible
  7.     form = '{:<20} {:6}   {:5.1f} / {:5.1f}, {:6.2f}%'
  8.     print(form.format(name, id, score_sum, max_possible, percent))
  9.  
  10. test_data = [
  11.     'Cross JP  900431 8.5  8.0 11.0  8.5  8.0 11.0  8.5  7.0 11.5  7.5',
  12.     'Dodd  AJ  900872 8.5  8.5 10.5  9.0 -1.0  9.5  9.5  7.0 12.0  5.0',
  13.     'Moss  WLM 901203 7.5 10.0 12.0  8.5  7.0 11.0 10.0 -1.0 13.0 -1.0',
  14.     'Ross  T   900398 7.5 -1.0 11.0  8.5  7.0 12.0  9.0 -1.0 12.5  8.0',
  15.     'Todd  BL  901197 9.0  8.0 -1.0  6.0  8.0  9.5 11.0 10.0 -1.0  6.0'
  16. ]
  17.  
  18. max_scores = [10.0, 10.0, 12.0, 9.0, 10.0, 12.0, 11.0, 10.0, 13.0, 8.0]
  19.  
  20. # Do not edit any of the code above this line.
  21. # One of the goals of this exercise is learning how to extract data items
  22. # from a string when the items are separated by spaces within the string.
  23.  
  24. # The next two statements are just tests to make sure the output
  25. # from print_grade_info looks reasonable.  Replace the statements
  26. # with code that will calculate and display assignment scores for
  27. # the students in test_data.
  28.  
  29. i = 0
  30. while i < len(test_data):
  31.     k = 3
  32.     achieved_grade = 0
  33.     total_grade = 105
  34.    
  35.     x = test_data[i].split()
  36.     while k < len(x):
  37.         if float(x[k]) > 0:
  38.             achieved_grade += float(x[k])
  39.         elif float(x[k]) == -1:
  40.             total_grade -= max_scores[k-3]
  41.         k += 1
  42.     print_grade_info(x[0], x[1], x[2], achieved_grade, total_grade)
  43.     i += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement