0% found this document useful (0 votes)
5 views

p2

p2

Uploaded by

vijipoovi24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

p2

p2

Uploaded by

vijipoovi24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

PYTHON

UNIT2
If Statement:
 The if statement is the most simple decision-making statement.
 It is used to decide whether a certain statement or block of statements will be
executed or not.

Flowchart of If Statement :

Syntax of If Statement in Python :


if expression:
statement

Example:
a = 33
b = 200
if b > a:
print("b is greater than a")
Output:
b is greater than a
Python Elif Statement:
 Here, a user can decide among multiple options. The if statements are executed from
the top down.
 As soon as one of the conditions controlling the if is true, the statement associated with
that if is executed, and the rest of the ladder is bypassed. If none of the conditions is
true, then the final “else” statement will be executed.
Flowchart of Elif Statement in Python:

Example:
a = 33

b = 33

if b > a:

print("b is greater than a")

elif a == b:

print("a and b are equal")

Output:
a and b are equal.
Python else statement:

 The else keyword is used in conditional statements (if statements), and


decides what to do if the condition is False.
 The else keyword can also be use in try...except blo
cks, see example below.

Flowchart else statement:

Example:

x = 2
if x > 3:
print("YES")
else:
print("NO")

Output:

No

You might also like