SHARE
TWEET

Code Mess

edman270 Mar 19th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. lloyd = {
  2.   "name": "Lloyd",
  3.   "homework": [90.0, 97.0, 75.0, 92.0],
  4.   "quizzes": [88.0, 40.0, 94.0],
  5.   "tests": [75.0, 90.0]
  6. }
  7. alice = {
  8.   "name": "Alice",
  9.   "homework": [100.0, 92.0, 98.0, 100.0],
  10.   "quizzes": [82.0, 83.0, 91.0],
  11.   "tests": [89.0, 97.0]
  12. }
  13. tyler = {
  14.   "name": "Tyler",
  15.   "homework": [0.0, 87.0, 75.0, 22.0],
  16.   "quizzes": [0.0, 75.0, 78.0],
  17.   "tests": [100.0, 100.0]
  18. }
  19.  
  20. # Add your function below!
  21. def average(values):
  22.     total = float(sum(values))
  23.     count = len(values)
  24.     return total / count
  25.  
  26. #returns weighted average for a student
  27. def get_average(student):
  28.   total = average(student['homework']) * 0.1 + average(student['quizzes']) * 0.3 + average(student['tests']) * .6
  29.   return total
  30.  
  31. #returns letter grade from a percentage
  32. def get_letter_grade(percentage):
  33.     grade = 'X'
  34.     if percentage >= 90:
  35.         grade = 'A'
  36.     elif percentage >= 80:
  37.         grade = 'B'
  38.     elif percentage >= 70:
  39.         grade = 'C'
  40.     elif percentage >= 60:
  41.         grade = 'D'
  42.     else:
  43.         grade = 'F'
  44.     return grade
  45.  
  46. #returns a class average
  47.  
  48. print get_letter_grade(get_average(lloyd))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top