If else in Python
An “if else in Python” works irrespective of what the expression’s value is. If the outcome is true then the code block that is succeeding the expression would get executed. If not, the code under the else block will run.
Decision-making is needed in Python to execute code only if a particular condition is fulfilled. The if-else statement is applied in Python for decision-making.
Syntax:
if expression:
statement(s)
else:
statement(s)
Example Program:
amount = int(input(“Enter amount: “))
if amount<1000:
discount = amount*0.05
print (“Discount”,discount)
else:
discount = amount*0.10
print (“Discount”,discount)
print (“Net payable:”,amount-discount)