grades.py - grades.py Walker M White(wmw2"Grade Sheet...

Info icon This preview shows page 1. Sign up to view the full content.

# grades.py # Walker M. White (wmw2) # September 30, 2012 """Grade Sheet Example for Dictionaries""" # Global variable store the grade sheet GRADES = {'js1':80,'js2':92,'wmw2':50,'aa1':95} def max_grade(grades): """Returns: maximum grade in the grade dictionary Precondition: grades has netids as keys, ints as values""" maximum = 0 for v in grades.values(): if v > maximum: maximum = v return maximum def netids_above_cutoff1(grades,cutoff): """Returns: list of netids with grades above or equal cutoff Precondition: grades has netids as keys, ints as values. cutoff is an int.""" result = [] # start with an empty list for k in grades.keys(): if grades[k] >= cutoff: result.append(k) # Add k to the list result return result def netids_above_cutoff2(grades,cutoff): """Returns: list of netids with grades above or equal cutoff Precondition: grades has netids as keys, ints as values.
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cutoff is an int.""" result = # start with an empty list for k,v in grades.items(): if v >= cutoff: # NOTE: Alternate way to append to list result = result+[k] # Put k in a list and concatenate to end return result def give_extra_credit(grades,netids,bonus): """Gives bonus points to everyone in sequence netids This is a PROCEDURE. It modifies the contents of grades. It only modifies elements of grades with a key that appears in the sequence netids. Precondition: grades has netids as keys, ints as values. netids is a sequence of strings whose elements are all keys in grades (though not all keys appear in netids). Bonus is an int.""" for student in netids: if student in grades: # tests if student is a key in grades grades[student] = grades[student]+bonus...
View Full Document

  • Fall '07
  • Amenta
  • Musical notation, netIDs, equal cutoff

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern