# Video Pending

# 29: Boolean Practice

The logic combinations you learned from the last exercise are called "Boolean" logic expressions. Boolean logic is used *everywhere* in programming. It is a fundamental part of computation, and knowing them very well is akin to knowing your scales in music.

In this exercise you will take the logic exercises you memorized and start trying them out in Python. Take each of these logic problems and write what you think the answer will be. In each case it will be either True or False. Once you have the answers written down, you will start Python in your terminal and type each logic problem in to confirm your answers.

`True and True`

`False and True`

`1 == 1 and 2 == 1`

`"test" == "test"`

`1 == 1 or 2 != 1`

`True and 1 == 1`

`False and 0 != 0`

`True or 1 == 1`

`"test" == "testing"`

`1 != 0 and 2 == 1`

`"test" != "testing"`

`"test" == 1`

`not (True and False)`

`not (1 == 1 and 0 != 1)`

`not (10 == 1 or 1000 == 1000)`

`not (1 != 10 or 3 == 4)`

`not ("testing" == "testing" and "Zed" == "Cool Guy")`

`1 == 1 and (not ("testing" == 1 or 1 == 0))`

`"chunky" == "bacon" and (not (3 == 4 or 3 == 3))`

`3 != 3 and (not ("testing" == "testing" or "Python" == "Fun"))`

I will also give you a trick to help you figure out the more complicated ones toward the end.

Whenever you see these Boolean logic statements, you can solve them easily by this simple process:

- Find an equality test (== or !=) and replace it with its truth.
- Find each
`and/or`

inside parentheses and solve those first. - Find each
`not`

and invert it. - Find any remaining
`and/or`

and solve it. - When you are done you should have True or False.

I will demonstrate with a *variation* on #20:

```
3 != 4 and not ("testing" != "test" or "Python" == "Python")
```

Here's me going through each of the steps and showing you the translation until I've boiled it down to a single result:

Solve each equality test:

`3 != 4`

is`True`

, so replace that with`True`

to get`True and not ("testing" != "test" or "Python" == "Python")`

`"testing" != "test"`

is`True`

so replace*that*with`True`

to get`True and not (True or "Python" == "Python")`

`"Python" == "Python"`

is True so replace that with`True`

and we have`True and not (True or True)`

Find each

`and/or`

in parentheses ():`(True or True)`

is`True`

so replace that to get`True and not (True)`

Find each

`not`

and invert it:`not (True)`

is`False`

so replace that and we have`True and False`

Find any remaining

`and/or`

and solve them:`True and False`

is`False`

and you're done.

With that we're done and know the result is False.

*very*hard at first. You should be able to take a good first stab at solving them, but do not get discouraged. I'm just getting you primed for more of these "logic gymnastics" so that later cool stuff is much easier. Just stick with it, and keep track of what you get wrong, but do not worry that it's not getting in your head quite yet. It'll come.

## Register for Learn Python the Hard Way, 5th Edition (2023-2024)

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.