if-else Statement
An if......else statement works on the following principle:
- Execute the block of code inside the
if
statement if the expression evaluates toTrue
. After execution, return to the code outside of theif......else
block. - Execute the block of code inside the
else
statement if the expression evaluates toFalse
. After execution, return to the code outside of theif......else
block.
Example:
applePrice = 210
budget = 200
if (applePrice <= budget):
print("Alexa, add 1kg Apples to the cart.")
else:
print("Alexa, do not add Apples to the cart.")
Output:
Alexa, do not add Apples to the cart.