Conditional statements
We can write conditional statements in Python. The conditional flow can be achieved with the if keyword. It is used in combination with a Boolean expression. If the expression returns True, then the block listed under if is executed. In Python, code blocks are denoted with indentation. In fact, indentation is the only way to create a code block (unlike { and } in C, C++, and Java). Following is an example of the usage of the if statement:
num = int(input("Enter a number :"))
if num > 10 :
print("The entered number is greater than 10.")
Run the program and see the output. We can enhance our logic with the else clause as follows:
num = int(input("Enter a number :"))
if num > 10 :
print("The entered number is greater than 10.")
else:
print("The entered number is less than or equal to 10.")
We can also create an elif ladder as...