Module 14 Assignments

Short Project 11

Due date: Dec 10, Tuesday at 7pm

Short Programming projects are submitted during our weekly 45-minute in-person lab sessions. Each lab sessions is guided by two TAs. The instructions for the short project will be available only during the lab sessions. To schedule your lab session go to the weekly lab session spreadsheet.

Programming Problems

Programming Problems should be submitted to gradescope.

Programming Problem 27

Due date: Dec 10, Tuesday at 7pm

Write a Python function that does the following:

  1. Its name is swap
  2. It takes two arguments: a dictionary and a set
  3. It swaps the key and value for all of the keys that exist in the dictionary that also exist in the set
  4. It does not return anything

Test cases:

dict_data = {'a':'b', 'c':'d', 'e':'f'}
set_data = {'c', 'e'}
swap(dict_data, set_data)
print(dict_data) # {'a': 'b', 'd': 'c', 'f': 'e'}

dict_data = {23:24, 110:120, 50:45, 70:50, 57:1}
set_data = {23, 110, 57}
swap(dict_data, set_data)
print(dict_data) # {50: 45, 70: 50, 24: 23, 120: 110, 1: 57}

dict_data = {23:24, 110:120, 50:45, 70:50, 57:1}
set_data = {100}
swap(dict_data, set_data)
print(dict_data) # {23:24, 110:120, 50:45, 70:50, 57:1}

Name the program swap_structures.py. Make sure that gradescope gives you the points for passing the test case.

Programming Problem 28

Due date: Oct 8, Tuesday at 7pm

Write a Python function that does the following:

  1. Its name is get_elements
  2. It two arguments: a dictionary with strings as keys and integers as values, and an integer n
  3. It returns a list containing all of the values who fall into at least one of these three categories:
    • The corresponding key starts with an upper-case letter
    • The corresponding key ends with an upper-case letter
    • The value is greater than or equal to the second parameter integer

Test cases:

data = {'Alpha':10, 'bravo':25, 'charliE':15, 'dELTa':2}
print( get_elements(data, 12) ) # [10, 25, 15]

Name the program get_specific.py. Make sure that gradescope gives you the points for passing the test case.