if elif else conditional statement:
Python IF condition helps to develop code based on logical conditions. In general, taking some action based on some condition is ‘true’ or ‘false’ is possible to accomplish by IF ELIF ELSE condition.
Note: Whenever user enters input value, Python converts that in to ‘STRING’ by DEFAULT.
Example: Creating simple calculator using Python ‘IF’ condition
num1 = float(input("Enter first number: "))
op = input("Enter operator: ")
num2 = float(input("Enter second number: "))
if op == '+':
===>print(num1 + num2)
elif op == '-':
===>print(num1 - num2)
elif op == '/':
===>print(num1 / num2)
elif op == '*':
===>print(num1 * num2)
else:
===>print("Invalid Operator")
Result 1:
Enter first number: 4
Enter operator: +
Enter second number: 6
10.0
Result 2:
Enter first number: 4
Enter operator: abc
Enter second number: 6
Invalid Operator