SlideShare a Scribd company logo
1 of 18
Python Control Statements
Indentation in Python
Indentation in Python
• In Python, indentation is used to declare a block. If two
statements are at the same indentation level, then they are
the part of the same block.
• For the ease of programming and to achieve simplicity, python
doesn't allow the use of curly braces or parentheses for the
block level code.
• Indentation is the most used part of the python programming
language.
• Generally, a tab space or four spaces are given to indent the
statements in python.
Conditional Statements in Python
Conditional Statements in Python
• Conditional Statements performs different computations or
actions depending on conditions.
• In python, the following are conditional statements
o if
o if –else
o if – elif –else
If statement:
• The if statement is used to test a specific condition. If the
condition is true, a block of code (if-block) will be executed.
Syntax:
if condition:
statement1
statement2
Conditional Statements in Python Cont..
Example: ifdemo.py
a = 33
b = 200
if b > a:
print ("b is greater than a")
print ("done…")
Remember:
input () function is used to get input from user.
Example:
a=input (“Enter a value”)
Output:
python ifdemo.py
b is greater than a
done…
Conditional Statements in Python Cont..
If-else statement:
• The if-else statement provides an else block combined with the if
statement which is executed in the false case of the condition.
Syntax:
if condition:
#block of statements
else:
#another block of statements (else-block)
Example: ifelsedemo.py
age = int(input("Enter your age : "))
if age>=18:
print("You are eligible to vote !!")
else:
print("Sorry! you have to wait !!"))
Output:
python ifelsedemo.py
Enter your age: 19
You are eligible to vote!!
Conditional Statements in Python Cont..
If-elif-else statement:
• The elif statement enables us to check multiple conditions and
execute the specific block of statements depending upon the true
condition among them.
Syntax:
if condition1:
# block of statements
elif condition2:
# block of statements
elif condition3:
# block of statements
else:
# block of statements
Conditional Statements in Python Cont..
Example: maxnum.py
a=int(input("Enter a value : "))
b=int(input("Enter b value : "))
c=int(input("Enter c value : "))
if (a>b) and (a>c):
print("Maximum value is :",a)
elif (b>a) and (b>c):
print("Maximum value is :",b)
else:
print("Maximum value is :",c)
Output:
python maxnum.py
Enter a value: 10
Enter b value: 14
Enter c value: 9
Maximum value is: 14
Loop Statements in Python
Loop Statements in Python
• Sometimes we may need to alter the flow of the program. If the
execution of a specific code may need to be repeated several
numbers of times then we can go for loop statements.
• In python, the following are loop statements
o while loop
o for loop
while loop:
• With the while loop we can execute a set of statements as long
as a condition is true. The while loop is mostly used in the case
where the number of iterations is not known in advance.
Syntax:
while expression:
Statement(s)
Loop Statements in Python Cont..
Using else with while loop
• Python enables us to use the while loop with the else block
also. The else block is executed when the condition given in
the while statement becomes false.
Example: whiledemo.py
i=1;
while i<=3:
print(i);
i=i+1;
Output:
python whiledemo.py
1
2
3
Example: wedemo.py
i=1;
while i<=3:
print(i);
i=i+1;
else:
print("while loop terminated")
Output:
python wedemo.py
1
2
3
while loop terminated
Loop Statements in Python Cont..
for loop:
• The for loop in Python is used to iterate the statements or a
part of the program several times. It is frequently used to
traverse the data structures like list, tuple, or dictionary.
Syntax:
for iterating_var in sequence:
statement(s)
Example: fordemo.py
i=1
n=int(input("Enter n value : "))
for i in range(i,n+1):
print(i,end = ' ')
Output:
python fordemo.py
Enter n value: 5
1 2 3 4 5
Loop Statements in Python Cont..
Using else with for loop
• Python allows us to use the else statement with the for loop
which can be executed only when all the iterations are
exhausted.
• Here, we must notice that if the loop contains any of the
break statement then the else statement will not be executed.
Example: fedemo.py
for i in range(1,5):
print(i,end=' ')
else:
print("for loop completely exhausted");
Output:
python fedemo.py
1 2 3 4
for loop completely exhausted
Jump Statements in Python
Jump Statements in Python
• Jump statements in python are used to alter the flow of a loop
like you want to skip a part of a loop or terminate a loop.
• In python, the following are jump statements
o break
o continue
break:
• The break is a keyword in python which is used to bring the
program control out of the loop.
• The break statement breaks the loops one by one, i.e., in the
case of nested loops, it breaks the inner loop first and then
proceeds to outer loops.
• The break is commonly used in the cases where we need to
break the loop for a given condition.
Syntax: break
Jump Statements in Python Cont..
continue:
• The continue statement in python is used to bring the program
control to the beginning of the loop.
• The continue statement skips the remaining lines of code inside
the loop and start with the next iteration.
• It is mainly used for a particular condition inside the loop so
that we can skip some specific code for a particular condition.
Syntax: continue
Example: breakdemo.py
i = 1
while i < 6:
print(i)
if i == 3:
break
i += 1
Output:
python breakdemo.py
1
2
3
Jump Statements in Python Cont..
Example: continuedemo.py
str =input("Enter any String : ")
for i in str:
if i == 'h':
continue;
print(i,end=" ");
Output:
python continuedemo.py
Enter any String : python
p y t o n

More Related Content

What's hot

Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Janki Shah
 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonLooping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonPriyankaC44
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Neeru Mittal
 
Control structures functions and modules in python programming
Control structures functions and modules in python programmingControl structures functions and modules in python programming
Control structures functions and modules in python programmingSrinivas Narasegouda
 
file handling c++
file handling c++file handling c++
file handling c++Guddu Spy
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in pythonTMARAGATHAM
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams Ahmed Farag
 
Programming Methodology
Programming MethodologyProgramming Methodology
Programming Methodologyarchikabhatia
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements Tarun Sharma
 
Python Fundamentals
Python FundamentalsPython Fundamentals
Python FundamentalsSherif Rasmy
 
Functions in python
Functions in pythonFunctions in python
Functions in pythoncolorsof
 
Conditional statement
Conditional statementConditional statement
Conditional statementMaxie Santos
 

What's hot (20)

Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
The Loops
The LoopsThe Loops
The Loops
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++
 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonLooping Statements and Control Statements in Python
Looping Statements and Control Statements in Python
 
Looping in C
Looping in CLooping in C
Looping in C
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
 
Interface in java
Interface in javaInterface in java
Interface in java
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
 
Control structures functions and modules in python programming
Control structures functions and modules in python programmingControl structures functions and modules in python programming
Control structures functions and modules in python programming
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
file handling c++
file handling c++file handling c++
file handling c++
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
Programming Methodology
Programming MethodologyProgramming Methodology
Programming Methodology
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Python Fundamentals
Python FundamentalsPython Fundamentals
Python Fundamentals
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
Conditional statement
Conditional statementConditional statement
Conditional statement
 

Similar to Control_Statements_in_Python.pptx

Python Decision Making And Loops.pdf
Python Decision Making And Loops.pdfPython Decision Making And Loops.pdf
Python Decision Making And Loops.pdfNehaSpillai1
 
6 Iterative Statements.pptx
6 Iterative Statements.pptx6 Iterative Statements.pptx
6 Iterative Statements.pptxssuser8e50d8
 
Conditional Statements.pptx
Conditional Statements.pptxConditional Statements.pptx
Conditional Statements.pptxGautam623648
 
ppt python notes list tuple data types ope
ppt python notes list tuple data types opeppt python notes list tuple data types ope
ppt python notes list tuple data types opeSukhpreetSingh519414
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1Devashish Kumar
 
if else python.pdf
if else python.pdfif else python.pdf
if else python.pdfGshs6
 
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KRLoops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KRKrishna Raj
 
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...jaychoudhary37
 

Similar to Control_Statements_in_Python.pptx (20)

Python Decision Making And Loops.pdf
Python Decision Making And Loops.pdfPython Decision Making And Loops.pdf
Python Decision Making And Loops.pdf
 
Control structures pyhton
Control structures  pyhtonControl structures  pyhton
Control structures pyhton
 
6 Iterative Statements.pptx
6 Iterative Statements.pptx6 Iterative Statements.pptx
6 Iterative Statements.pptx
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
Conditional Statements.pptx
Conditional Statements.pptxConditional Statements.pptx
Conditional Statements.pptx
 
ppt python notes list tuple data types ope
ppt python notes list tuple data types opeppt python notes list tuple data types ope
ppt python notes list tuple data types ope
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1
 
Unit - 2 CAP.pptx
Unit - 2 CAP.pptxUnit - 2 CAP.pptx
Unit - 2 CAP.pptx
 
Ch-4.pdf
Ch-4.pdfCh-4.pdf
Ch-4.pdf
 
Python revision tour i
Python revision tour iPython revision tour i
Python revision tour i
 
if else python.pdf
if else python.pdfif else python.pdf
if else python.pdf
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KRLoops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
 
C++ programming
C++ programmingC++ programming
C++ programming
 
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
 
C++ programming
C++ programmingC++ programming
C++ programming
 
com.pptx
com.pptxcom.pptx
com.pptx
 
85ec7 session2 c++
85ec7 session2 c++85ec7 session2 c++
85ec7 session2 c++
 
iterations.docx
iterations.docxiterations.docx
iterations.docx
 

More from Koteswari Kasireddy

Chapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdfChapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdfKoteswari Kasireddy
 
Object_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdfObject_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdfKoteswari Kasireddy
 
Relational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptxRelational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptxKoteswari Kasireddy
 
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxUnit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxKoteswari Kasireddy
 
Database System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxDatabase System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxKoteswari Kasireddy
 
parts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxparts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxKoteswari Kasireddy
 

More from Koteswari Kasireddy (20)

DA Syllabus outline (2).pptx
DA Syllabus outline (2).pptxDA Syllabus outline (2).pptx
DA Syllabus outline (2).pptx
 
Chapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdfChapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdf
 
Object_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdfObject_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdf
 
unit-3_Chapter1_RDRA.pdf
unit-3_Chapter1_RDRA.pdfunit-3_Chapter1_RDRA.pdf
unit-3_Chapter1_RDRA.pdf
 
DBMS_UNIT_1.pdf
DBMS_UNIT_1.pdfDBMS_UNIT_1.pdf
DBMS_UNIT_1.pdf
 
business analytics
business analyticsbusiness analytics
business analytics
 
Relational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptxRelational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptx
 
CHAPTER -12 it.pptx
CHAPTER -12 it.pptxCHAPTER -12 it.pptx
CHAPTER -12 it.pptx
 
WEB_DATABASE_chapter_4.pptx
WEB_DATABASE_chapter_4.pptxWEB_DATABASE_chapter_4.pptx
WEB_DATABASE_chapter_4.pptx
 
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxUnit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
 
Database System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxDatabase System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptx
 
Evolution Of WEB_students.pptx
Evolution Of WEB_students.pptxEvolution Of WEB_students.pptx
Evolution Of WEB_students.pptx
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
Python_Functions_Unit1.pptx
Python_Functions_Unit1.pptxPython_Functions_Unit1.pptx
Python_Functions_Unit1.pptx
 
parts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxparts_of_python_programming_language.pptx
parts_of_python_programming_language.pptx
 
linked_list.pptx
linked_list.pptxlinked_list.pptx
linked_list.pptx
 
matrices_and_loops.pptx
matrices_and_loops.pptxmatrices_and_loops.pptx
matrices_and_loops.pptx
 
algorithms_in_linkedlist.pptx
algorithms_in_linkedlist.pptxalgorithms_in_linkedlist.pptx
algorithms_in_linkedlist.pptx
 
Control_Statements.pptx
Control_Statements.pptxControl_Statements.pptx
Control_Statements.pptx
 

Recently uploaded

BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
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
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
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
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 

Recently uploaded (20)

BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
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
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
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...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
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
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 

Control_Statements_in_Python.pptx

  • 3. Indentation in Python • In Python, indentation is used to declare a block. If two statements are at the same indentation level, then they are the part of the same block. • For the ease of programming and to achieve simplicity, python doesn't allow the use of curly braces or parentheses for the block level code. • Indentation is the most used part of the python programming language. • Generally, a tab space or four spaces are given to indent the statements in python.
  • 5. Conditional Statements in Python • Conditional Statements performs different computations or actions depending on conditions. • In python, the following are conditional statements o if o if –else o if – elif –else If statement: • The if statement is used to test a specific condition. If the condition is true, a block of code (if-block) will be executed. Syntax: if condition: statement1 statement2
  • 6. Conditional Statements in Python Cont.. Example: ifdemo.py a = 33 b = 200 if b > a: print ("b is greater than a") print ("done…") Remember: input () function is used to get input from user. Example: a=input (“Enter a value”) Output: python ifdemo.py b is greater than a done…
  • 7. Conditional Statements in Python Cont.. If-else statement: • The if-else statement provides an else block combined with the if statement which is executed in the false case of the condition. Syntax: if condition: #block of statements else: #another block of statements (else-block) Example: ifelsedemo.py age = int(input("Enter your age : ")) if age>=18: print("You are eligible to vote !!") else: print("Sorry! you have to wait !!")) Output: python ifelsedemo.py Enter your age: 19 You are eligible to vote!!
  • 8. Conditional Statements in Python Cont.. If-elif-else statement: • The elif statement enables us to check multiple conditions and execute the specific block of statements depending upon the true condition among them. Syntax: if condition1: # block of statements elif condition2: # block of statements elif condition3: # block of statements else: # block of statements
  • 9. Conditional Statements in Python Cont.. Example: maxnum.py a=int(input("Enter a value : ")) b=int(input("Enter b value : ")) c=int(input("Enter c value : ")) if (a>b) and (a>c): print("Maximum value is :",a) elif (b>a) and (b>c): print("Maximum value is :",b) else: print("Maximum value is :",c) Output: python maxnum.py Enter a value: 10 Enter b value: 14 Enter c value: 9 Maximum value is: 14
  • 11. Loop Statements in Python • Sometimes we may need to alter the flow of the program. If the execution of a specific code may need to be repeated several numbers of times then we can go for loop statements. • In python, the following are loop statements o while loop o for loop while loop: • With the while loop we can execute a set of statements as long as a condition is true. The while loop is mostly used in the case where the number of iterations is not known in advance. Syntax: while expression: Statement(s)
  • 12. Loop Statements in Python Cont.. Using else with while loop • Python enables us to use the while loop with the else block also. The else block is executed when the condition given in the while statement becomes false. Example: whiledemo.py i=1; while i<=3: print(i); i=i+1; Output: python whiledemo.py 1 2 3 Example: wedemo.py i=1; while i<=3: print(i); i=i+1; else: print("while loop terminated") Output: python wedemo.py 1 2 3 while loop terminated
  • 13. Loop Statements in Python Cont.. for loop: • The for loop in Python is used to iterate the statements or a part of the program several times. It is frequently used to traverse the data structures like list, tuple, or dictionary. Syntax: for iterating_var in sequence: statement(s) Example: fordemo.py i=1 n=int(input("Enter n value : ")) for i in range(i,n+1): print(i,end = ' ') Output: python fordemo.py Enter n value: 5 1 2 3 4 5
  • 14. Loop Statements in Python Cont.. Using else with for loop • Python allows us to use the else statement with the for loop which can be executed only when all the iterations are exhausted. • Here, we must notice that if the loop contains any of the break statement then the else statement will not be executed. Example: fedemo.py for i in range(1,5): print(i,end=' ') else: print("for loop completely exhausted"); Output: python fedemo.py 1 2 3 4 for loop completely exhausted
  • 16. Jump Statements in Python • Jump statements in python are used to alter the flow of a loop like you want to skip a part of a loop or terminate a loop. • In python, the following are jump statements o break o continue break: • The break is a keyword in python which is used to bring the program control out of the loop. • The break statement breaks the loops one by one, i.e., in the case of nested loops, it breaks the inner loop first and then proceeds to outer loops. • The break is commonly used in the cases where we need to break the loop for a given condition. Syntax: break
  • 17. Jump Statements in Python Cont.. continue: • The continue statement in python is used to bring the program control to the beginning of the loop. • The continue statement skips the remaining lines of code inside the loop and start with the next iteration. • It is mainly used for a particular condition inside the loop so that we can skip some specific code for a particular condition. Syntax: continue Example: breakdemo.py i = 1 while i < 6: print(i) if i == 3: break i += 1 Output: python breakdemo.py 1 2 3
  • 18. Jump Statements in Python Cont.. Example: continuedemo.py str =input("Enter any String : ") for i in str: if i == 'h': continue; print(i,end=" "); Output: python continuedemo.py Enter any String : python p y t o n