SlideShare a Scribd company logo
1 of 19
Subject :- Python
Topic :- Conditional
Statement
Guided by:-
Mr. Jeetendra sir
Submitted by:-
Aashna Behra
MCA1st (Sem)
Department Of Computer Science & Application
CONDITIONAL STATEMENT
• There comes situations in real life when we need to
make some decisions and based on these decisions,
we decide what should we do next.
• Similar situations arise in programming also where
we need to make some decisions and based on these
decisions we will execute the next block of code.
• Python programming language provide there
functionality to handle these types of situation using
conditional statement which it also known as decision
making statement like if, if else, elif, nested if, nested
if else.
IF STATEMENT
• 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 that is if a certain
condition is true then a block of statement is executed
otherwise not.
Syntax: if <condition> :
#statements of if
It executes if when the condition becomes true
Introduction to the if Statement
• The condition after evaluation will be either true or
false.
• If the statement accepts boolean values - if the
value is true then it will execute the block of
statements below it otherwise not.
• We can use condition with bracket (‘’) also.
• Python uses indentation to identify a block.
Example of if statement :
If ELSE
• The if statement alone tells us that if a condition is true
it will execute a block of statements and if the condition
is false it won’t.
• But what if we want to do something else if the
condition in false.
• Here comes the else statement.
• We can use the else statement with if statement to
execute a block of code when the condition if false.
Syntax of if else :
if <condition> :
#statement
#executes this block if condition is true
else :
#statement
#executes this block else condition is true & if is false
Example of if else :
Elif Statement
• In python we have one more conditional statement called
“elif” statement.
• “Elif” statement is used to check multiple condition is false.
• It’s similar to an “if – else” statement and the only
difference is that in “else” we will not check the condition
but in “elif” we will check the condition .
• “Elif” statements are similar to “if else” statements but
“elif” statements evaluate multiple condition.
Syntax of Elif Statement :
if <condition>:
#set of statement to execute if condition is true
elif <condition>
#set of statements to be executed when if condition is
false and elif condition is true
else:
#set of statement to be executed when both if and elif
conditions are false
Example of Elif Statement :
Nested if Else Statement :
• Nested “if else” statements mean that an “if” statement
or “if else” statement is present inside another if or if
else block.
• Python provides this feature as well, this in turn will
help us to check multiple conditions in a given program.
• An “if” statement is present inside another “if”
statement which is present inside another “if” statement
and so on.
Syntax of Nested if :
if <condition>
#statements to execute if condition is true
if <condition>
#statements to execute if condition is
true
#end of nested if
#end of if
• The above syntax clearly says that the if block will contain
another if block in it and so on.
• If block can contain ‘n’ number of if block inside it.
Example of Nested If :
Syntax of Nested If Else :
if <condition>:
#statements to execute if condition is true
if <condition>:
#statements to execute if condition is true
else:
#statements to execute if condition Is false
else:
#statements to execute if condition is false
Example of Nested if else :
THANK
YOU

More Related Content

What's hot

Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in pythonTMARAGATHAM
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in PythonSujith Kumar
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An IntroductionSwarit Wadhe
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming LanguageDipankar Achinta
 
Python Collections Tutorial | Edureka
Python Collections Tutorial | EdurekaPython Collections Tutorial | Edureka
Python Collections Tutorial | EdurekaEdureka!
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide shareDevashish Kumar
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonNowell Strite
 
Python PPT
Python PPTPython PPT
Python PPTEdureka!
 
Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiersNilimesh Halder
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaPython Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaEdureka!
 
Error and exception in python
Error and exception in pythonError and exception in python
Error and exception in pythonjunnubabu
 

What's hot (20)

Python programming : Control statements
Python programming : Control statementsPython programming : Control statements
Python programming : Control statements
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Type conversion
Type conversionType conversion
Type conversion
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
 
Python Collections Tutorial | Edureka
Python Collections Tutorial | EdurekaPython Collections Tutorial | Edureka
Python Collections Tutorial | Edureka
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Python
PythonPython
Python
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Python PPT
Python PPTPython PPT
Python PPT
 
Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiers
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaPython Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
 
Chapter 03 python libraries
Chapter 03 python librariesChapter 03 python libraries
Chapter 03 python libraries
 
Error and exception in python
Error and exception in pythonError and exception in python
Error and exception in python
 
Python Modules
Python ModulesPython Modules
Python Modules
 

Similar to python conditional statement.pptx

W4-DecisionMaking.pdf. python document. CS
W4-DecisionMaking.pdf. python document. CSW4-DecisionMaking.pdf. python document. CS
W4-DecisionMaking.pdf. python document. CSMalikaKhan21
 
Conditionalstatement
ConditionalstatementConditionalstatement
ConditionalstatementRaginiJain21
 
Control satkcher ppt
Control satkcher pptControl satkcher ppt
Control satkcher ppt6336Zeelvora
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETUjwala Junghare
 
05 Conditional statements
05 Conditional statements05 Conditional statements
05 Conditional statementsmaznabili
 
STATEMENT’S AND LOOP’S
STATEMENT’S AND LOOP’SSTATEMENT’S AND LOOP’S
STATEMENT’S AND LOOP’SBilalAhmed802
 
Cse lecture-6-c control statement
Cse lecture-6-c control statementCse lecture-6-c control statement
Cse lecture-6-c control statementFarshidKhan
 
C++ unit-1-part-15
C++ unit-1-part-15C++ unit-1-part-15
C++ unit-1-part-15Jadavsejal
 
All about decision making statements in php
All about decision making statements in phpAll about decision making statements in php
All about decision making statements in phpPrograming Code Example
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)TejaswiB4
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsEng Teong Cheah
 
RaspberryPi & Python Workshop Day - 02.pptx
RaspberryPi & Python Workshop Day - 02.pptxRaspberryPi & Python Workshop Day - 02.pptx
RaspberryPi & Python Workshop Day - 02.pptxShivanshSeth6
 

Similar to python conditional statement.pptx (20)

W4-DecisionMaking.pdf. python document. CS
W4-DecisionMaking.pdf. python document. CSW4-DecisionMaking.pdf. python document. CS
W4-DecisionMaking.pdf. python document. CS
 
Conditionalstatement
ConditionalstatementConditionalstatement
Conditionalstatement
 
Python decision making
Python   decision makingPython   decision making
Python decision making
 
PRESENTATION.pptx
PRESENTATION.pptxPRESENTATION.pptx
PRESENTATION.pptx
 
Control_Statements.pptx
Control_Statements.pptxControl_Statements.pptx
Control_Statements.pptx
 
Computer programming 2 Lesson 9
Computer programming 2  Lesson 9Computer programming 2  Lesson 9
Computer programming 2 Lesson 9
 
Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7
 
Control satkcher ppt
Control satkcher pptControl satkcher ppt
Control satkcher ppt
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NET
 
05 Conditional statements
05 Conditional statements05 Conditional statements
05 Conditional statements
 
STATEMENT’S AND LOOP’S
STATEMENT’S AND LOOP’SSTATEMENT’S AND LOOP’S
STATEMENT’S AND LOOP’S
 
Cse lecture-6-c control statement
Cse lecture-6-c control statementCse lecture-6-c control statement
Cse lecture-6-c control statement
 
C++ unit-1-part-15
C++ unit-1-part-15C++ unit-1-part-15
C++ unit-1-part-15
 
All about decision making statements in php
All about decision making statements in phpAll about decision making statements in php
All about decision making statements in php
 
Python Programming Part 3.pdf
Python Programming Part 3.pdfPython Programming Part 3.pdf
Python Programming Part 3.pdf
 
Python Programming Part 3.pdf
Python Programming Part 3.pdfPython Programming Part 3.pdf
Python Programming Part 3.pdf
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & Loops
 
RaspberryPi & Python Workshop Day - 02.pptx
RaspberryPi & Python Workshop Day - 02.pptxRaspberryPi & Python Workshop Day - 02.pptx
RaspberryPi & Python Workshop Day - 02.pptx
 
Using decision statements
Using decision statementsUsing decision statements
Using decision statements
 

More from Dolchandra

Abhishek kurre.pptx
Abhishek kurre.pptxAbhishek kurre.pptx
Abhishek kurre.pptxDolchandra
 
Hitesh Dewangan PPT.pptx
Hitesh Dewangan PPT.pptxHitesh Dewangan PPT.pptx
Hitesh Dewangan PPT.pptxDolchandra
 
AASHUrdbms.pptx
AASHUrdbms.pptxAASHUrdbms.pptx
AASHUrdbms.pptxDolchandra
 
Window to Viewport Transformation in Computer Graphics with.pptx
Window to Viewport Transformation in Computer Graphics with.pptxWindow to Viewport Transformation in Computer Graphics with.pptx
Window to Viewport Transformation in Computer Graphics with.pptxDolchandra
 
dinning phillosopher problem
dinning phillosopher problemdinning phillosopher problem
dinning phillosopher problemDolchandra
 
Window to Viewport Transformation in Computer Graphics with.pptx
Window to Viewport Transformation in Computer Graphics with.pptxWindow to Viewport Transformation in Computer Graphics with.pptx
Window to Viewport Transformation in Computer Graphics with.pptxDolchandra
 

More from Dolchandra (8)

Abhishek kurre.pptx
Abhishek kurre.pptxAbhishek kurre.pptx
Abhishek kurre.pptx
 
Hitesh Dewangan PPT.pptx
Hitesh Dewangan PPT.pptxHitesh Dewangan PPT.pptx
Hitesh Dewangan PPT.pptx
 
AASHUrdbms.pptx
AASHUrdbms.pptxAASHUrdbms.pptx
AASHUrdbms.pptx
 
Window to Viewport Transformation in Computer Graphics with.pptx
Window to Viewport Transformation in Computer Graphics with.pptxWindow to Viewport Transformation in Computer Graphics with.pptx
Window to Viewport Transformation in Computer Graphics with.pptx
 
rdbmsdol.pptx
rdbmsdol.pptxrdbmsdol.pptx
rdbmsdol.pptx
 
dinning phillosopher problem
dinning phillosopher problemdinning phillosopher problem
dinning phillosopher problem
 
rdbmsdol.pptx
rdbmsdol.pptxrdbmsdol.pptx
rdbmsdol.pptx
 
Window to Viewport Transformation in Computer Graphics with.pptx
Window to Viewport Transformation in Computer Graphics with.pptxWindow to Viewport Transformation in Computer Graphics with.pptx
Window to Viewport Transformation in Computer Graphics with.pptx
 

Recently uploaded

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

python conditional statement.pptx

  • 1. Subject :- Python Topic :- Conditional Statement Guided by:- Mr. Jeetendra sir Submitted by:- Aashna Behra MCA1st (Sem) Department Of Computer Science & Application
  • 2.
  • 3. CONDITIONAL STATEMENT • There comes situations in real life when we need to make some decisions and based on these decisions, we decide what should we do next. • Similar situations arise in programming also where we need to make some decisions and based on these decisions we will execute the next block of code. • Python programming language provide there functionality to handle these types of situation using conditional statement which it also known as decision making statement like if, if else, elif, nested if, nested if else.
  • 4. IF STATEMENT • 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 that is if a certain condition is true then a block of statement is executed otherwise not. Syntax: if <condition> : #statements of if It executes if when the condition becomes true
  • 5. Introduction to the if Statement
  • 6. • The condition after evaluation will be either true or false. • If the statement accepts boolean values - if the value is true then it will execute the block of statements below it otherwise not. • We can use condition with bracket (‘’) also. • Python uses indentation to identify a block.
  • 7. Example of if statement :
  • 8. If ELSE • The if statement alone tells us that if a condition is true it will execute a block of statements and if the condition is false it won’t. • But what if we want to do something else if the condition in false. • Here comes the else statement. • We can use the else statement with if statement to execute a block of code when the condition if false.
  • 9. Syntax of if else : if <condition> : #statement #executes this block if condition is true else : #statement #executes this block else condition is true & if is false
  • 10. Example of if else :
  • 11. Elif Statement • In python we have one more conditional statement called “elif” statement. • “Elif” statement is used to check multiple condition is false. • It’s similar to an “if – else” statement and the only difference is that in “else” we will not check the condition but in “elif” we will check the condition . • “Elif” statements are similar to “if else” statements but “elif” statements evaluate multiple condition.
  • 12. Syntax of Elif Statement : if <condition>: #set of statement to execute if condition is true elif <condition> #set of statements to be executed when if condition is false and elif condition is true else: #set of statement to be executed when both if and elif conditions are false
  • 13. Example of Elif Statement :
  • 14. Nested if Else Statement : • Nested “if else” statements mean that an “if” statement or “if else” statement is present inside another if or if else block. • Python provides this feature as well, this in turn will help us to check multiple conditions in a given program. • An “if” statement is present inside another “if” statement which is present inside another “if” statement and so on.
  • 15. Syntax of Nested if : if <condition> #statements to execute if condition is true if <condition> #statements to execute if condition is true #end of nested if #end of if • The above syntax clearly says that the if block will contain another if block in it and so on. • If block can contain ‘n’ number of if block inside it.
  • 17. Syntax of Nested If Else : if <condition>: #statements to execute if condition is true if <condition>: #statements to execute if condition is true else: #statements to execute if condition Is false else: #statements to execute if condition is false
  • 18. Example of Nested if else :