Practical use of booleans


#1

Hi i do understand how the boolean works but i don't now why but i am not able to imagine it's pactical use some examples would be amazing.

Thk


#2

Easy use:

Suppose you have a video game you made.

In this game, you can enter "Cheat Codes" to allow certain extra features.

If they enter a correct Cheat Code, then you want to turn on ( Change to True ) a variable.

Example:

def cheats(input):
    if input == "God_Mode":
        infinite_health = True
    elif input == "sPeEdY":
        super_speed = True

If they enter a correct code, then they will get max health, or super speed to use.


#3

thk great help i got confused what is the benefit of "not" statement can you give some examples


#4

You could use not in many ways.

I use it the most for checking strings.

Example:

if letter not in "aeiou":
    #Do Something