MWZ

MINDWAREZONE

if-else Statement in python

An if...else statement follows this logic:

  • If the condition evaluates to True, the code inside the if block is executed. Once it finishes, the program continues with the code that follows the if...else structure.
  • If the condition evaluates to False, the code inside the else block is executed. After that, the program proceeds to the code outside the if...else structure.
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.")
            
Alexa, do not add Apples to the cart.