0% found this document useful (0 votes)
2 views13 pages

Main Python

Conditional statements in Python allow programs to make decisions based on conditions that evaluate to True or False. The main types include if statements, if-else statements, if-elif-else ladders, and nested if statements, each serving different decision-making needs. Mastering these constructs enhances the ability to write dynamic and efficient code.

Uploaded by

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

Main Python

Conditional statements in Python allow programs to make decisions based on conditions that evaluate to True or False. The main types include if statements, if-else statements, if-elif-else ladders, and nested if statements, each serving different decision-making needs. Mastering these constructs enhances the ability to write dynamic and efficient code.

Uploaded by

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

CONDITIONAL

STATEMENTS
IN PYTHON
WHAT ARE CONDITIONAL
STATEMENTS?
Conditional statements in Python are programming
constructs that allow a program to make decisions and
execute different blocks of code based on whether a
specified condition evaluates to True or False.
TYPES OF CONDITIONAL
STATEMENTS
1. if statement
2. if-else statement
3. if-elif-else ladder
4. Nested if
if Statement
This is the simplest conditional statement. It executes
a block of code only if the specified condition is true.

Syntax:
if condition:
# Code to be executed if condition is true
if Statement
Output:
Mississippi
End
if-else Statement
This is statement provides alternative block of code to execute
if the if condition is False.

Syntax:
if condition:
# Code to be executed if condition is true
else:
# Code to be executed if condition is false
if-else Statement
Output:
Mississippi
Finish
if-elif-else Statement
This allows for checking multiple conditions sequentially. If
the first if condition is false, it checks the elif (else if)
conditions in order. If none of the if or elif conditions are true,
the else block is executed.

Syntax:
if condition1:
# Code if condition1 is true
elif condition2:
# Code if condition2 is true
else:
# Code if no condition is true
if-elif-else Statement
Output:
Enter a no. 7
Mississippi
Finish!
Nested-if Statement
Conditional statements can be nested within other conditional
statements, allowing for more complex decision-making based
on multiple levels of conditions.

Syntax:
if condition1:
# Code if condition1 is true
if condition 2:
#Code if condition 2 is true
else:
#Code if condition 2 is false
else:
#Code if condition 1 is true
Nested-if Statement
Output:
Enter a no. 6
6 is a number greater
than 5.
Finish!
CONCLUSION
o Conditional statements are essential for adding logic and
decision-making to Python programs.

o Mastering if, if-else, and if-elif-else improves your ability


to write dynamic and responsive code.

o Proper use of conditional statements makes your programs


efficient, interactive, and closer to real-world scenarios.
THANK
YOU

You might also like