Skip to main content

Not

The NOT operator, represented by the tilde symbol (~), is used in the Nada DSL to invert or negate a boolean value. When applied to a boolean expression, the ~ operator flips its value—turning True to False and False to True.

src/not.py
from nada_dsl import *

def nada_main():
party_alice = Party(name="Alice")
party_bob = Party(name="Bob")
party_charlie = Party(name="Charlie")

secret_target = SecretInteger(Input(name="secret_target", party=party_alice))
secret_guess = SecretInteger(Input(name="secret_guess", party=party_bob))

# equal to check (==)
check_is_equal_to = secret_target == secret_guess

# the not operator (~) is used to invert or negate a boolean value
check_is_not_equal_to = ~check_is_equal_to

return [
Output(check_is_not_equal_to, "check_is_not_equal_to", party_charlie),
]

Run and test the not program

1. Open "Nada by Example"

Open in Gitpod

2. Run the program with inputs from the test file

nada run not_test_1

3. Test the program with inputs from the test file against the expected_outputs from the test file

nada test not_test_1
Feedback