Page 93 - Trackpad_V2.1_class8
P. 93
It contains a conditional expression , which is used to compare
Start
data. A decision is made based on the result of the comparison.
If the result of the expression is true, the statements within the
if block are executed and if the result of the expression is false, if condition False
the statements within the if block are not executed. There is no
limitation on the number of statements that can appear within True
the if block. Hence, you may add as many statements in the if Statements in if block
block as needed. The syntax of if statement is as follows: execute
if (conditional expression):
statement(s) Stop
Program 1: To check whether a given number is positive
Program1.py
File Edit Format Run Options Window Help
#Program to check if a number is positive
n = int (input ('Enter a number:'))
if(n > 0):
print('Entered number is positive number')
Output
Enter a number:35
Entered number is positive number
Subject: If statement execution criteria
A statement or statements indented within an if statement is executed
only if the condition is true, otherwise the control skips the if statement and
moves on to the statements outside the if block.
THE if-else STATEMENT
The if-else statement is used to evaluate whether a Start
given statement is true or false. If the given condition is
true, then statements within the if block are executed.
If the given condition is false, then statements within if condition
the else block are executed. The syntax of the if-else False
statement is as follows: True Statements in else
if (conditional expression): Statements in if block execute
statement(s) block execute
else:
statement(s) Stop
Control Structures in Python 91

