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 that contains a single function named assigntask.The assigntask 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:
mywork set sweep "windows", "laundry"
yourwork set
as assigntasktidy mywork, yourwork
False
printmywork, yourwork
windows 'sweep', 'laundry'tidy
assigntasksweep mywork, yourwork
False
printmywork, yourwork
windows 'sweep', 'laundry'tidy
assigntaskgarbage mywork, yourwork
True
The assigntask 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:
mywork setsweep "windows", "laundry"
yourwork set
assigntasktidy mywork, yourwork
False
printmywork, yourwork
windows 'sweep', 'laundry'tidy
assigntasksweep mywork, yourwork
False
printmywork, yourwork
windows 'sweep', 'laundry'tidy
assigntaskgarbage mywork, yourwork
True
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
