SlideShare a Scribd company logo
2
Most read
7
Most read
10
Most read
Python Flow Control
Class: XI
Computer Science-083
Introduction
Part-1
Python Flow Of Control
A program’s control flow is the order in which the program’s code executes. A Flow
Control Statement defines the flow of the execution of the Program. Control flow
statements are required to alter the flow of program execution based on the
conditions.
SEQUENTIAL :
SELECTION CONDITIONAL:
ITERATIVE / LOOPING:
It is classified into three categories:
Python Flow Of Control
SEQUENTIAL :
It to provide the order in which we execute our instructions.
Example: Program to display sum of two numbers.
A=10
B=12
sum=A+B
print(sum)
All the lines are in a
sequence
Python Flow Of Control
Decision-making statements : if, if..else, if..elif..else
SELECTION CONDITIONAL: Selection to allow decisions to be made.
Python Flow Of Control
Looping statements : for, while
Branching statements : break, continue
ITERATIVE / LOOPING:
Iteration to loop or repeat our instructions as many times as we
need.
Decision-making Statements or Conditional Statements
if Statement
if - else Statement
elif statements
The if statement is used to test a specific condition. If the condition is true, a block of
code or block of statements will be executed.
The if-else statement is similar to if statement except that, it also provides the block of
the code for the false case of the condition to be checked. If the condition provided in
the if statement is false, then the else statement will be executed.
In python, we have one more conditional statement called elif statements. elif
statement is used to check multiple conditions only if the given if condition 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 do check the condition.
Nested if-else statements
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.
elif Ladder
It means a program which contains ladder of elif statements or elif statements which are
structured in the form of a ladder.
This statement is used to test multiple expressions
What is for loop in Python?
Python Loops or Iteration
for loops
There are two types of loops in Python
Loops can execute a block of code number of times until a certain condition is met.
while loops While Loop is used to repeat a block of code. Instead of running the
code block once, It executes the code block multiple times until a
certain condition is met
In Python, "for loops" are called iterators.ust like while loop, "For Loop"
is also used to repeat the program. But unlike while loop which
depends on condition true or false. "For Loop" depends on the
elements it has to iterate
So first we discuss Decision-making Statements
if Statement
if - else Statement
elif statements
Nested if-else statements
elif Ladder
if Statement
The if statement is used to test a specific condition. If the condition is true only, a block
of code or block of statements will be executed.
Syntax:
if condition or expression:
-----Statements-------
-----Statements-------
Example: Program to check number is less than 10 , if yes
then display message "Number is smaller than 10"
no=5
If no<10:
print(“Number is smaller than 10”)
---Output----
Number is smaller than 10
This is indentation. Python relies on indentation (whitespace
at the beginning of a line) to define scope in the code
Let us understand the if condition indentation and scope with the help of another example:
Num = 5
if(Num < 10):
print(“Num is smaller than 10”)
print(“This statements will always be executed”)
---Output----
Number is smaller than 10
This statements will always be executed
Num = 15
if(Num < 10):
print(“Num is smaller than 10”)
print(“This statements will always be executed”)
---Output----
This statements will always be executed
Now in this case if we change the value of Num to 15, then if() condition not satisfied and
it not run the statement inside its scope , but last message will display it is because it not a
part of if condition , its out of its scope.
So in python indentation is very important to get a correct result.
If statement, without indentation (will raise an error)
a = 33
b = 200
if b > a:
print("b is greater than a")
For example , if we need to check that variable A is greater than B.
It display the error message , that
indentation missing.
a = 33
b = 200
if b > a:
print("b is greater than a")
Correct code is when we use proper indentation:
---Output----
B is greater than a
So now we know python indentation
Let take one more example: Write a program to accept the age of a person and check the
age is more than equal to 18, if yes than display ‘You are valid to vote’
age=int(input(“Enter the age:”))
if age>=18:
print(‘You are valid to vote’)
---Output----
Enter the age: 19
You are valid to vote
Now we use the logical operator AND , OR with if condition
OR with if condition:
Now if you want to display message “You select write number” if a user enter any one
number from the given list and the numbers are 1, 3, 5
no=int(input(“Enter the value[1 , 3 , 5]:”))
if (no==1 or no==3 or no == 5):
print(“You selected write number”)
---Output----
Enter the value[1,3,5]: 5
You selected write number
Now we use the logical operator AND , OR with if condition
AND with if condition:
Write a program to check the number is between 10 to 40 , if yes then print message that
“Your value in range of 10-40”
no=int(input(“Enter the value:”))
if (no>=10 and no<=40):
print(“You value in range of 10-40”)
---Output----
Enter the value: 15
Your value in range of 10-40
One important point the And is used for checking the range values. For Example:
How to use if’s without else part in a program
If’s condition:
Write a program to accept a number and print the following message:
If no is 1 “you selected 1” , if no is 2 “you selected 2” , if no is 3 “you selected 3”
no=int(input(“Enter the value:”))
if (no == 1):
print(“You selected 1”) ---Output----
Enter the value: 2
Your selected 2
if (no == 2):
print(“You selected 2”)
if (no == 3):
print(“You selected 3”)

More Related Content

What's hot (20)

PPSX
python Function
Ronak Rathi
 
PDF
2. python basic syntax
Soba Arjun
 
PPT
Python Control structures
Siddique Ibrahim
 
PPTX
Conditional and control statement
narmadhakin
 
PPTX
Looping Statements and Control Statements in Python
PriyankaC44
 
PPTX
Python basics
Hoang Nguyen
 
PPTX
Control Flow Statements
Tarun Sharma
 
PDF
Strings in python
Prabhakaran V M
 
PPTX
Operators in Python
Anusuya123
 
PPT
Introduction to Python
amiable_indian
 
PPTX
Control statements in c
Sathish Narayanan
 
PDF
Operators in python
Prabhakaran V M
 
PPTX
Python Functions
Mohammed Sikander
 
PDF
Python programming
Prof. Dr. K. Adisesha
 
PPTX
Functions in python
colorsof
 
PPSX
Programming with Python
Rasan Samarasinghe
 
PPTX
Python 3 Programming Language
Tahani Al-Manie
 
PPT
Strings
Nilesh Dalvi
 
PPT
While loop
Feras_83
 
PPTX
Looping statement in python
RaginiJain21
 
python Function
Ronak Rathi
 
2. python basic syntax
Soba Arjun
 
Python Control structures
Siddique Ibrahim
 
Conditional and control statement
narmadhakin
 
Looping Statements and Control Statements in Python
PriyankaC44
 
Python basics
Hoang Nguyen
 
Control Flow Statements
Tarun Sharma
 
Strings in python
Prabhakaran V M
 
Operators in Python
Anusuya123
 
Introduction to Python
amiable_indian
 
Control statements in c
Sathish Narayanan
 
Operators in python
Prabhakaran V M
 
Python Functions
Mohammed Sikander
 
Python programming
Prof. Dr. K. Adisesha
 
Functions in python
colorsof
 
Programming with Python
Rasan Samarasinghe
 
Python 3 Programming Language
Tahani Al-Manie
 
Strings
Nilesh Dalvi
 
While loop
Feras_83
 
Looping statement in python
RaginiJain21
 

Similar to FLOW OF CONTROL-INTRO PYTHON (20)

PDF
basic of desicion control statement in python
nitamhaske
 
PPTX
industry coding practice unit-2 ppt.pptx
LakshmiMarineni
 
PPTX
Week 4.pptx computational thinking and programming
cricketfundavlogs
 
PPTX
RaspberryPi & Python Workshop Day - 02.pptx
ShivanshSeth6
 
PDF
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
sdvdsvsdvsvds
 
PPTX
Conditional Statements.pptx
Gautam623648
 
PPTX
Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control S...
FabMinds
 
PDF
Unit 1- Part-2-Control and Loop Statements.pdf
Harsha Patil
 
PPTX
ControlStructures.pptx5t54t54444444444444444
pawankamal3
 
PDF
loops.pdf
AmayJaiswal4
 
PPTX
Control_Statements.pptx
Koteswari Kasireddy
 
PDF
E-Notes_3721_Content_Document_20250107032537PM.pdf
aayushihirpara297
 
PPTX
Python Flow Control & use of functions.pptx
pandyahm47
 
PDF
Python Decision Making And Loops.pdf
NehaSpillai1
 
PPTX
python.pptx
Poornima116356
 
PPTX
pds first unit module 2 MODULE FOR ppt.pptx
bmit1
 
PDF
Python unit 2 M.sc cs
KALAISELVI P
 
PPTX
1. control structures in the python.pptx
DURAIMURUGANM2
 
PPT
Control structures pyhton
Prakash Jayaraman
 
PDF
Slide 6_Control Structures.pdf
NuthalapatiSasidhar
 
basic of desicion control statement in python
nitamhaske
 
industry coding practice unit-2 ppt.pptx
LakshmiMarineni
 
Week 4.pptx computational thinking and programming
cricketfundavlogs
 
RaspberryPi & Python Workshop Day - 02.pptx
ShivanshSeth6
 
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
sdvdsvsdvsvds
 
Conditional Statements.pptx
Gautam623648
 
Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control S...
FabMinds
 
Unit 1- Part-2-Control and Loop Statements.pdf
Harsha Patil
 
ControlStructures.pptx5t54t54444444444444444
pawankamal3
 
loops.pdf
AmayJaiswal4
 
Control_Statements.pptx
Koteswari Kasireddy
 
E-Notes_3721_Content_Document_20250107032537PM.pdf
aayushihirpara297
 
Python Flow Control & use of functions.pptx
pandyahm47
 
Python Decision Making And Loops.pdf
NehaSpillai1
 
python.pptx
Poornima116356
 
pds first unit module 2 MODULE FOR ppt.pptx
bmit1
 
Python unit 2 M.sc cs
KALAISELVI P
 
1. control structures in the python.pptx
DURAIMURUGANM2
 
Control structures pyhton
Prakash Jayaraman
 
Slide 6_Control Structures.pdf
NuthalapatiSasidhar
 
Ad

More from vikram mahendra (20)

PPTX
Communication skill
vikram mahendra
 
PDF
Python Project On Cosmetic Shop system
vikram mahendra
 
PDF
Python Project on Computer Shop
vikram mahendra
 
PDF
PYTHON PROJECT ON CARSHOP SYSTEM
vikram mahendra
 
PDF
BOOK SHOP SYSTEM Project in Python
vikram mahendra
 
PPTX
FLOWOFCONTROL-IF..ELSE PYTHON
vikram mahendra
 
PPTX
OPERATOR IN PYTHON-PART1
vikram mahendra
 
PPTX
OPERATOR IN PYTHON-PART2
vikram mahendra
 
PPTX
USE OF PRINT IN PYTHON PART 2
vikram mahendra
 
PPTX
DATA TYPE IN PYTHON
vikram mahendra
 
PPTX
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
vikram mahendra
 
PPTX
USER DEFINE FUNCTIONS IN PYTHON
vikram mahendra
 
PPTX
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
vikram mahendra
 
PPTX
INTRODUCTION TO FUNCTIONS IN PYTHON
vikram mahendra
 
PPTX
Python Introduction
vikram mahendra
 
PPTX
GREEN SKILL[PART-2]
vikram mahendra
 
PPTX
GREEN SKILLS[PART-1]
vikram mahendra
 
PPTX
Dictionary in python
vikram mahendra
 
PPTX
Entrepreneurial skills
vikram mahendra
 
PPTX
Boolean logic
vikram mahendra
 
Communication skill
vikram mahendra
 
Python Project On Cosmetic Shop system
vikram mahendra
 
Python Project on Computer Shop
vikram mahendra
 
PYTHON PROJECT ON CARSHOP SYSTEM
vikram mahendra
 
BOOK SHOP SYSTEM Project in Python
vikram mahendra
 
FLOWOFCONTROL-IF..ELSE PYTHON
vikram mahendra
 
OPERATOR IN PYTHON-PART1
vikram mahendra
 
OPERATOR IN PYTHON-PART2
vikram mahendra
 
USE OF PRINT IN PYTHON PART 2
vikram mahendra
 
DATA TYPE IN PYTHON
vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON
vikram mahendra
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
vikram mahendra
 
INTRODUCTION TO FUNCTIONS IN PYTHON
vikram mahendra
 
Python Introduction
vikram mahendra
 
GREEN SKILL[PART-2]
vikram mahendra
 
GREEN SKILLS[PART-1]
vikram mahendra
 
Dictionary in python
vikram mahendra
 
Entrepreneurial skills
vikram mahendra
 
Boolean logic
vikram mahendra
 
Ad

Recently uploaded (20)

PPTX
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PPTX
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Introduction to Indian Writing in English
Trushali Dodiya
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Difference between write and update in odoo 18
Celine George
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Horarios de distribución de agua en julio
pegazohn1978
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
epi editorial commitee meeting presentation
MIPLM
 

FLOW OF CONTROL-INTRO PYTHON

  • 1. Python Flow Control Class: XI Computer Science-083 Introduction Part-1
  • 2. Python Flow Of Control A program’s control flow is the order in which the program’s code executes. A Flow Control Statement defines the flow of the execution of the Program. Control flow statements are required to alter the flow of program execution based on the conditions. SEQUENTIAL : SELECTION CONDITIONAL: ITERATIVE / LOOPING: It is classified into three categories:
  • 3. Python Flow Of Control SEQUENTIAL : It to provide the order in which we execute our instructions. Example: Program to display sum of two numbers. A=10 B=12 sum=A+B print(sum) All the lines are in a sequence
  • 4. Python Flow Of Control Decision-making statements : if, if..else, if..elif..else SELECTION CONDITIONAL: Selection to allow decisions to be made.
  • 5. Python Flow Of Control Looping statements : for, while Branching statements : break, continue ITERATIVE / LOOPING: Iteration to loop or repeat our instructions as many times as we need.
  • 6. Decision-making Statements or Conditional Statements if Statement if - else Statement elif statements The if statement is used to test a specific condition. If the condition is true, a block of code or block of statements will be executed. The if-else statement is similar to if statement except that, it also provides the block of the code for the false case of the condition to be checked. If the condition provided in the if statement is false, then the else statement will be executed. In python, we have one more conditional statement called elif statements. elif statement is used to check multiple conditions only if the given if condition 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 do check the condition.
  • 7. Nested if-else statements 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. elif Ladder It means a program which contains ladder of elif statements or elif statements which are structured in the form of a ladder. This statement is used to test multiple expressions
  • 8. What is for loop in Python? Python Loops or Iteration for loops There are two types of loops in Python Loops can execute a block of code number of times until a certain condition is met. while loops While Loop is used to repeat a block of code. Instead of running the code block once, It executes the code block multiple times until a certain condition is met In Python, "for loops" are called iterators.ust like while loop, "For Loop" is also used to repeat the program. But unlike while loop which depends on condition true or false. "For Loop" depends on the elements it has to iterate
  • 9. So first we discuss Decision-making Statements if Statement if - else Statement elif statements Nested if-else statements elif Ladder
  • 10. if Statement The if statement is used to test a specific condition. If the condition is true only, a block of code or block of statements will be executed. Syntax: if condition or expression: -----Statements------- -----Statements------- Example: Program to check number is less than 10 , if yes then display message "Number is smaller than 10" no=5 If no<10: print(“Number is smaller than 10”) ---Output---- Number is smaller than 10 This is indentation. Python relies on indentation (whitespace at the beginning of a line) to define scope in the code
  • 11. Let us understand the if condition indentation and scope with the help of another example: Num = 5 if(Num < 10): print(“Num is smaller than 10”) print(“This statements will always be executed”) ---Output---- Number is smaller than 10 This statements will always be executed Num = 15 if(Num < 10): print(“Num is smaller than 10”) print(“This statements will always be executed”) ---Output---- This statements will always be executed Now in this case if we change the value of Num to 15, then if() condition not satisfied and it not run the statement inside its scope , but last message will display it is because it not a part of if condition , its out of its scope.
  • 12. So in python indentation is very important to get a correct result. If statement, without indentation (will raise an error) a = 33 b = 200 if b > a: print("b is greater than a") For example , if we need to check that variable A is greater than B. It display the error message , that indentation missing. a = 33 b = 200 if b > a: print("b is greater than a") Correct code is when we use proper indentation: ---Output---- B is greater than a
  • 13. So now we know python indentation Let take one more example: Write a program to accept the age of a person and check the age is more than equal to 18, if yes than display ‘You are valid to vote’ age=int(input(“Enter the age:”)) if age>=18: print(‘You are valid to vote’) ---Output---- Enter the age: 19 You are valid to vote
  • 14. Now we use the logical operator AND , OR with if condition OR with if condition: Now if you want to display message “You select write number” if a user enter any one number from the given list and the numbers are 1, 3, 5 no=int(input(“Enter the value[1 , 3 , 5]:”)) if (no==1 or no==3 or no == 5): print(“You selected write number”) ---Output---- Enter the value[1,3,5]: 5 You selected write number
  • 15. Now we use the logical operator AND , OR with if condition AND with if condition: Write a program to check the number is between 10 to 40 , if yes then print message that “Your value in range of 10-40” no=int(input(“Enter the value:”)) if (no>=10 and no<=40): print(“You value in range of 10-40”) ---Output---- Enter the value: 15 Your value in range of 10-40 One important point the And is used for checking the range values. For Example:
  • 16. How to use if’s without else part in a program If’s condition: Write a program to accept a number and print the following message: If no is 1 “you selected 1” , if no is 2 “you selected 2” , if no is 3 “you selected 3” no=int(input(“Enter the value:”)) if (no == 1): print(“You selected 1”) ---Output---- Enter the value: 2 Your selected 2 if (no == 2): print(“You selected 2”) if (no == 3): print(“You selected 3”)