1a# Goal:# Given a set, add a new element to the set.# Inputs:# major_appliances is a set containing major appliances.# new_appliance is an element.# Outputs:# The function should return the set with added new_appliance in the set.def q1a(major_appliances, new_appliance): # Insert your code return major_appliances
# 1b# Goal:# Given a set, remove an element from the set.# Input:# job_titles is a set containing job titles.# invalid_job is a job that is no longer relevant in modern world.# Output:# The function should return the set with invalid_job removed.def q1b(job_titles, invalid_job): # Insert your code return job_titles
# 1c# Goal:# Given two sets, combine two sets.# Input:# cyber_students is a set containing names of cyber security students.# data_students is a set containing names of data analytics students.# Output:# The function should return a set containing the names of students either in cyber secruity and/or data analytics.def q1c(cyber_students, data_students): # Insert your code return {} # swap to inf_students
# 1d# Goal:# Given a list, convert it to a set.# Input:# message_list is a list containing strings of messages.# Output:# The function should return a set of messages.def q1d(message_list): # Insert your code return {} # swap to message_set
# 1e# Goal:# Given a tuple, return a list.# Input:# tup1 is a tuple containing various data types.# Output:# The function should return the first three elements of the tup1 as a list,# OR return an empty list if the tup1 has length of 3 or less.def q1e(tup1): # Insert your code return [] # swap to the correct value
# 1f# Goal:# Given two sets and a number, return a list.# Input:# set_one and set_two are sets, each containing a set of numbers.# repeat_num is a number.# Output:# The function should return a list made from the intersection of set_one and set_two and repeated repeat_num times.# For example, if set_one has {'a', 'b'}, set_two has {'b', 'c', 'd'}, and 3 is the repeat_num.# The output from this specific example should be repeated_list = ['b', 'b', 'b']# If the repeat_num is 0 or there is no intersection, return an empty list.def q1f(set_one, set_two, repeat_num): # Insert your code return [] # swap to the correct value
# 2a# Goal:# Given a list, find sum, average, max, and return them as a tuple.# Input:# number_list contains random numbers# Output:# The function should return sum of all negative numbers, average of all numbers, biggest number from the list as a tuple in specified order.# For example, if the number_list contained [-5, -2, -1, 0, 3], return results_tup that contains (-8, -1, 3)def q2a(number_list): # Insert you code return (0, 0, 0) # swap to results_tup that contains correct values
# 2b# Goal:# Given two sets, find union, intersection, difference, and return them as a tuple.# Input:# set_a contains a set of things.# set_b contains a set of things.# Output:# The function should return a tuple that contains 4 things.# union of two sets,# intersection of the first set with the second set,# differences from the first set to the second set,# and differences from the second set to the first set.def q2b(set_a, set_b): # Insert your code return (0, 0, 0) # swap to correct values
# 2c# Goal:# Given a dictionary, use a tuple key to return a value.# Given two input parameters, construct the tuple key.# Input:# input_dict is a dictionary.# a is a number.# b is a string.# Output:# The function should return the value based on the tuple key.def q2c(input_dict, a, b): # Insert your code return [] # swap to correct value
# Test# Tells you which test case the program has failed in terminal.# These are examples of test cases provided for you to test your program during the homework.# All test cases should pass.# Uncomment the class when you want to test your program!
class TestQuestion1A(unittest.TestCase): def test_one(self): self.assertEqual(q1a({'Oven', 'Washer', 'Dishwasher'}, 'Fridge'), {'Oven', 'Washer', 'Dishwasher', 'Fridge'})
def test_two(self): self.assertEqual(q1a({'TV', 'AC', 'Microwave'}, 'Projector'), {'TV', 'AC', 'Microwave', 'Projector'})
class TestQuestion1B(unittest.TestCase): def test_one(self): self.assertEqual(q1b({'Teacher', 'Chef', 'Human Alarm Clock'}, 'Human Alarm Clock'), {'Teacher', 'Chef'})
def test_two(self): self.assertEqual(q1b({'Artist', 'Musician', 'Programmer', 'Switchboard Operator'}, 'Switchboard Operator'), {'Artist', 'Musician', 'Programmer'})
class TestQuestion1C(unittest.TestCase): def test_one(self): self.assertEqual(q1c({'Ariel', 'Fish', 'Sebatian'}, {'Apple', 'Dwarf', 'Snow White'}), {'Dwarf', 'Apple', 'Fish', 'Snow White', 'Ariel', 'Sebatian'})
def test_two(self): self.assertEqual(q1c({'Steve Jobs', 'Bill Gates'}, {'Mark Zuckerberg', 'Jeff Bezos'}), {'Steve Jobs', 'Bill Gates', 'Mark Zuckerberg', 'Jeff Bezos'})
class TestQuestion1D(unittest.TestCase): def test_one(self): self.assertEqual(q1d(['hi', 'this', 'is', 'some', 'secret', 'message']), {'hi', 'this', 'is', 'some', 'secret', 'message'})
def test_two(self): self.assertEqual(q1d(['list', 0, 'messages']), {'list', 0, 'messages'})
class TestQuestion1E(unittest.TestCase): def test_one(self): self.assertEqual(q1e((1, 'hello', [5, 10], 8, 9, 10)), [1, 'hello', [5, 10]])
def test_two(self): self.assertEqual(q1e(('too', 'short')), [])
class TestQuestion1F(unittest.TestCase): def test_one(self): self.assertEqual(q1f({'a', 'b'}, {'b', 'c'}, 1), ['b'])
def test_two(self): self.assertEqual(sorted(q1f({1, 3, 5, 7, 9}, {7, 9, 11}, 2)), [7, 7, 9, 9])
def test_three(self): self.assertEqual(q1f({'a'},{'a', 'b'}, 0), [])
def test_four(self): self.assertEqual(q1f({1, 3, 5}, {2, 4}, 2), [])
class TestQuestion2A(unittest.TestCase): def test_one(self): self.assertEqual(q2a([1, 2, 3, 4, 5]), (15, 3.0, 5))
def test_two(self): self.assertEqual(q2a([10, 20, 30]), (60, 20.0, 30))
class TestQuestion2B(unittest.TestCase): def test_one(self): self.assertEqual(q2b({1, 'a', 2, 'b', 3, 'c'},{1, 'c', 3, 'e', 5}), ({1, 2, 3, 5, 'e', 'b', 'a', 'c'}, {1, 'c', 3}, {2, 'b', 'a'}, {'e', 5}))
def test_two(self): self.assertEqual(q2b({"I love programming", 'fun', 'summer', 308}, {'surviving', 'summer', 'class'}), ({'surviving', 308, 'fun', 'class', 'summer', 'I love programming'}, {'summer'}, {'I love programming', 'fun', 308}, {'surviving', 'class'}))
class TestQuestion2C(unittest.TestCase): def test_one(self): self.assertEqual(q2c({(1, 'a'): 'Yay!', ('a', 1): 'Such Fun!'}, 1, 'a'), 'Yay!')
def test_two(self): self.assertEqual(q2c({(5, 'five'): "I am five", ('five', 5): "I am also five"}, 5, 'five'), "I am five")
if __name__ == '__main__': unittest.main()