Question: For this exercise you will write Python code to assist in fairly dividing up tasks between two roommates. You must create a file named tasks.py

For this exercise you will write Python code to assist in fairly dividing up tasks between two roommates. You must create a file named tasks.py assign.py (updated 9/24) that contains a single function named assign_task.The assign_task function must take three arguments: a string representing the new task, and
two sets containing the tasks that have already been assigned. The function must return a
Boolean indicating whether the resulting assignment is fair. A fair assignment is any assignment
such that number of elements in each set differs by at most one. Task assignments must satisfy
the following requirements:
There can be no duplicate tasks. If a task already exists in either set, it must be ignored. You
may assume that there will not be duplicate tasks in the provided sets.
New tasks must be added to the set that currently has fewest items. In the case of a tie, the
task must be added to the set associated with the first set argument.
The following interaction provides some examples of the expected behavior:
my_work = set (["sweep", "windows", "laundry"])
your_work = set ()
as assign_task("tidy", my_work, your_work)
False
print(my_work, your_work)
{'windows', 'sweep', 'laundry'}{'tidy'}
assign_task("sweep", my_work, your_work)
False
print(my_work, your_work)
{'windows', 'sweep', 'laundry'}{'tidy'}
assign_task("garbage", my_work, your_work)
True
The assign_task function must take three arguments: a string representing the new task, and two sets containing the tasks that have already been assigned. The function must return a Boolean indicating whether the resulting assignment is fair. A fair assignment is any assignment such that number of elements in each set differs by at most one. Task assignments must satisfy the following requirements:
There can be no duplicate tasks. If a task already exists in either set, it must be ignored. You may assume that there will not be duplicate tasks in the provided sets.
New tasks must be added to the set that currently has fewest items. In the case of a tie, the task must be added to the set associated with the first set argument.
The following interaction provides some examples of the expected behavior:
>>> my_work = set(["sweep", "windows", "laundry"])
>>> your_work = set()
>>> assign_task("tidy", my_work, your_work)
False
>>> print(my_work, your_work)
{'windows', 'sweep', 'laundry'}{'tidy'}
>>> assign_task("sweep", my_work, your_work)
False
>>> print(my_work, your_work)
{'windows', 'sweep', 'laundry'}{'tidy'}
>>> assign_task("garbage", my_work, your_work)
True
 For this exercise you will write Python code to assist in

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!