if-else Statement

 if-else Statement

An if……else statement works on the following principle,


  • execute the block of code inside if statement if the expression evaluates True. After execution return to the code out of the if……else block.
  • execute the block of code inside else statement if the expression evaluates False. After execution return to the code out of the if……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.