Skip to content

IPP-DEV-02-004: Booleans #61

@labbenchstudios

Description

@labbenchstudios

Description

  • Using instructions from the in-class lecture, create a module to test some simple boolean operations.

Review the README

  • Please see README.md for further information on, and use of, this content.
  • License for embedded documentation and source codes: IPP-DOC-LIC

Estimated effort may vary greatly

  • The estimated level of effort for this exercise shown in the 'Estimate' section below is a very rough approximation. The actual level of effort may vary greatly depending on your development and test environment, experience with the requisite technologies, and many other factors.

Actions

Step 1: Make Sure Your System is Setup for Python and This Course

Step 2: REMINDER: Make Sure PYTHONPATH is Set Correctly

Whether running Python tests within your IDE or from the command line, you must set the PYTHONPATH environment variable in every execution environment (e.g., every terminal you launch) when attempting to run any of your scripts and their tests or the IPP test app from the command line. The IPP source and test paths will be as follows:

  • {your IPP source code path}
  • {your IPP source code path}/tests

See IPP-DEV-01-001 for details.

Step 3: Create your own module to test simple numeric calculations

  • Using your IDE, or from within a terminal, create a new Python file - a module - named SimpleBooleans.py within the labmodule02 path (or package)
  • Open the module, and create the indicated test cases:

Test 1 (bool declare)

  • Create a comment at the beginning of the file:
    • For example:
    • # Test 1: bool declare test
  • Declare the is_enabled variable as a bool. Set the value to True
  • Write an if statement testing the value of is_enabled - if it's True, print a statement indicating such. Here's an example:
    • NOTE: Be sure to use 4 spaces to indent the print line after the if statement.
if (is_enabled):
    print("The boolean `is_enabled` is", is_enabled)

Test 2 (bool compare)

  • Within the same module, add a blank newline after the previous test, and create another comment:
    • For example:
    • # Test 2: bool compare test
  • Declare the is_running variable as a bool. Set the value to False
  • Write an if clause testing the if is_running and is_enabled are equivalent. Use the == operator for this.
    • If they're equivalent, print a statement indicating such.
    • If they're not equivalent, print a statement indicating such along with their values.
    • Here's an example:
      • NOTE: Be sure to use 4 spaces to indent the print line after the if statement and after the else clause.
if (is_running == is_enabled):
    print("The booleans `is_running` and `is_enabled` have the same value:", is_running)
else:
    print(f"The booleans `is_running = {is_running}` and `is_enabled = {is_enabled}` differ.")

Estimate

  • Small

Tests

  • From within your IDE

    • Right click on your newly created module SimpleBooleans.py and click your IDE's run icon
    • You should see output similar to that discussed in class
  • From the command line

    • Open a terminal and cd to your IPP_HOME path
    • Start your virtual environment (if not already running)
    • Be sure your PYTHONPATH is set correctly
    • Run the module
      • python ./labmodule02/SimpleBooleans.py
    • You should see output similar to that discussed in class

Sample output (yours may differ slightly)

First test (is_enabled and is_running differ)

  • Set is_enabled to True
  • Set is_running to False
The boolean `is_enabled` is True
The booleans `is_running = False` and `is_enabled = True` differ.

Second test (is_enabled and is_running are the same)

  • Set is_enabled to True
  • Set is_running to True
The boolean `is_enabled` is True
The booleans `is_running` and `is_enabled` have the same value: True

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Lab Module 02 - Syntax

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions