Instructions for combineBooleans

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:

  • Zero or more assignments of local variables to boolean expressions, where each boolean expression can consist only of combinations of the function parameters and previously defined local variables using the logical operator not, and, and or;
  • A final statement in which 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.

Notes

  • You may assume that all four arguments are boolean values. Your function does not need to check that the arguments might be non-bool values.
  • Because of the limited form of the function body, the definition of atLeastTwoTrue must not use any kinds of expresions or statements not explicitly specified above. In particular, it must not use:
    • conditionals (if statements/expressions);
    • loops (while or for)
    • calls to any built-in functions (e.g., str), helper functions, or even recursive function calls to atLeastTwoTrue itself;
    • any operators other than not, and, or or. In particular, prohibited operators include arithmetic operators (e.g., +, -) and relational operators (e.g., <, ≤. ==. !=. ≥. >).
  • You are not allowed to defined and use any helper functions.
  • You should strive to make your code as understandable as possible, using comments to explain any aspects of your code that are not obvious.
  • As an extra challenge, you should try to minimize the total number of ocurrences of logical operators (not, and, or) that appear in your definition. Prof. Lyn's solution uses **16** logical operator occurrences; can you beat this?
  • You can test your current version of 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.

Examples

atLeastTwoTrue Examples

The following examples are 8 of 16 possible calls that show how atLeastTwoTrue should work:

In []:
atLeastTwoTrue(False, False, False, False)
Out[]:
False
In []:
atLeastTwoTrue(True, False, False, False)
Out[]:
False
In []:
atLeastTwoTrue(False, False, True, False)
Out[]:
False
In []:
atLeastTwoTrue(True, True, False, False)
Out[]:
True
In []:
atLeastTwoTrue(False, True, False, True)
Out[]:
True
In []:
atLeastTwoTrue(False, True, True, True)
Out[]:
True
In []:
atLeastTwoTrue(True, True, False, True)
Out[]:
True
In []:
atLeastTwoTrue(True, True, True, True)
Out[]:
True

Rubric

This task does not have an explicit list of rubric items. But here are some things to focus on:
  • Your atLeastTwoTrue function definition should be correct: it should return the correct boolean
    result for each of the 16 possible combinations of four boolean inputs.
  • Your definition should be easy to understand. Use comments and local variable definitions with
    well-chosen, meaningful names to make it clear why the function calculates the correct result.
  • Your definition should be efficient in the sense that it should perform as few logical operations
    as possible.