In the previous article, you learned about the
The python programming language have a separate block of code to execute when the
Example – if-then-else
Let us take out previous example of
# Declaring cash available for purchase cashAvailable = 5000 # price of item with tax price = 5000 tax = 200 # The if-block executes if the price + tax is less than or equal to cash if cashAvailable >= price + tax: print("Purchase Successful", price + tax) # The else will tell what to do if cash available is less else: print("Insufficient Cash ! Purchase cannot be done!") print("Transaction Complete!")
The output of the program will be as follows.
Insufficient Cash! Purchase cannot be done! Transaction Complete!
The program first check if