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...

1 answer below »
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()
Answered Same DayJun 13, 2021

Answer To: 1a# Goal:# Given a set, add a new element to the set.# Inputs:# major_appliances is a set containing...

Rushendra answered on Jun 14 2021
152 Votes
py_code/.pytest_cache/.gitignore
# Created by pytest automatically.
*
py_code/.pytest_cache/CACHEDIR.TAG
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by pytest.
# For information about cache directory tags, see:
#    http://www.bford.info/cachedir/spec.html
py_code/.pytest_cache/README.
md
# pytest cache directory #
This directory contains data from the pytest's cache plugin,
which provides the `--lf` and `--ff` options, as well as the `cache` fixture.
**Do not** commit this to version control.
See [the docs](https://docs.pytest.org/en/stable/cache.html) for more information.
py_code/.pytest_cache/v/cache/nodeids
[
"assignmt3_test.py::TestQuestion1A::test_one",
"assignmt3_test.py::TestQuestion1A::test_two",
"assignmt3_test.py::TestQuestion1B::test_one",
"assignmt3_test.py::TestQuestion1B::test_two",
"assignmt3_test.py::TestQuestion1C::test_one",
"assignmt3_test.py::TestQuestion1C::test_two",
"assignmt3_test.py::TestQuestion1D::test_one",
"assignmt3_test.py::TestQuestion1D::test_two",
"assignmt3_test.py::TestQuestion1E::test_one",
"assignmt3_test.py::TestQuestion1E::test_two",
"assignmt3_test.py::TestQuestion1F::test_four",
"assignmt3_test.py::TestQuestion1F::test_one",
"assignmt3_test.py::TestQuestion1F::test_three",
"assignmt3_test.py::TestQuestion1F::test_two",
"assignmt3_test.py::TestQuestion2A::test_one",
"assignmt3_test.py::TestQuestion2A::test_two",
"assignmt3_test.py::TestQuestion2B::test_one",
"assignmt3_test.py::TestQuestion2B::test_two",
"assignmt3_test.py::TestQuestion2C::test_one",
"assignmt3_test.py::TestQuestion2C::test_two"
]
py_code/.pytest_cache/v/cache/stepwise
[]
py_code/.vscode/settings.json
{
"python.testing.pytestArgs": [
"."
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.unittestArgs": [
"-v",
"-s",
".",
"-p",
"*_test.py"
]
}
py_code/assignmt3_test.py
import unittest
import sys
### YOUR NAME HERE
### TUPLES AND SETS
### The file name should be renamed to your Student ID (00XXXXXXX_hw3.py)
### Each question in section 1 is worth 9 points.
### Each question in section 2 is worth 12 points. (List advanced, Dict advanced, Tuple advanced, + extra credit)
### Your programs should pass the provided test cases.
### Read the instructions and examples for each question.
### Find the insert-your-code messages!
### When you want to test your program, uncomment the appropriate test case from bottom, run the program.
### Depending on the test results, modify the code or move to the next question.
### The questions are separate, and the earlier results do not affect your ability to complete other question.
### Do not modify the structure of the code.
### Start of HW3
# 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
major_appliances.add(new_appliance)
return major_appliances
# 1b
# Goal:
# Given...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here