This task is part of project02 which is due at 23:00 EST on 2026-09-17.
This is an individual task that you must do on your own.
You can download the starter code for this task using this link.
See how to submit this task using this link.
Put all of your work for this task into the file
combineBooleans.py
(which is provided among the starter files)
This task gives you practice with defining a complicated predicate and using the logical operations not, and, and or in your definition.
Your goal is to flesh out the skeleton definition of predicate atLeastTwoTrue that is provided in the starter file combineBooleans.py. This predicate takes four boolean values as its arguments. It returns True if at least two of its four arguments are True; otherwise it returns False. See these examples.
You are extremely limited in terms of the structure of the body of the definition of atLeastTwoTrue. The statements in this body must consist of:
not, and, and or;
return returns the value of a boolean expression of thea same form described in the previous bullet point.
The constrained form of the definition of atLeastTwoTrue will force you to think carefully about how boolean expressions involving the parameter names and optional local variables that you define can correctly calculate the boolean that should be returned by the function.
not
need to check that the arguments might be non-bool values.
atLeastTwoTrue must not use any kinds of expresions or statements not explicitly specified above. In particular, it must not use:
if statements/expressions); while or for)str),
helper functions, or even recursive function
calls to atLeastTwoTrue itself;not, and, or or.
In particular, prohibited operators include arithmetic operators (e.g., +,
-) and relational operators (e.g., <,
≤.
==.
!=.
≥.
>).
not, and, or)
that appear in your definition. Prof. Lyn's solution uses **16** logical operator
occurrences; can you beat this?atLeastTwoTrue by
(1) saving the the file combineBooleans.py and
(2) running the program test_combineBooleans.py.
The latter program will test your atLeastTwoTrue definition on
all 16 possible combinations of the four boolean arguments, reporting any
combination of arguments for which your function returns the wrong result.
It will also perform some tests that verify it doesn't use any of the
prohibted constructrs described above.
You'll know that your definition of atLeastTwoTrue is correct
when running test_combineBooleans.py shows only checkmarks
and no Xs.atLeastTwoTrue Examples
The following examples are 8 of 16 possible calls that show how atLeastTwoTrue should work:
In []:Out[]:atLeastTwoTrue(False, False, False, False)In []:FalseOut[]:atLeastTwoTrue(True, False, False, False)In []:FalseOut[]:atLeastTwoTrue(False, False, True, False)In []:FalseOut[]:atLeastTwoTrue(True, True, False, False)In []:TrueOut[]:atLeastTwoTrue(False, True, False, True)In []:TrueOut[]:atLeastTwoTrue(False, True, True, True)In []:TrueOut[]:atLeastTwoTrue(True, True, False, True)In []:TrueOut[]:atLeastTwoTrue(True, True, True, True)True
atLeastTwoTrue function definition should be
correct:
it should return the correct boolean