Binary Decisions
if and else statements
if and else statements
if (boolean condition):
# if's code block
code here
else:
# else's code block
# end of the conditionals
code continues hereThe if’s code block only execute if its boolean condition is True
The else’s code block will execute only when the if’s boolean condition is False
This helps us create two pathways in our code
# Code Example 1
num = 100
if num < 0 and num > 100:
print(num, 'is invalid.')
else:
print(num)
# since the if statement's condition is False we get to execute just the print(num) statementLast updated