SlideShare a Scribd company logo
1 of 16
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

Python If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | EdurekaPython If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | EdurekaEdureka!
 
Python Decision Making
Python Decision MakingPython Decision Making
Python Decision MakingSoba Arjun
 
Python Control structures
Python Control structuresPython Control structures
Python Control structuresSiddique Ibrahim
 
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAChapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAMaulik Borsaniya
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statementnarmadhakin
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data typesMohd Sajjad
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Paige Bailey
 
Data types in python
Data types in pythonData types in python
Data types in pythonRaginiJain21
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception HandlingMegha V
 
Control Structures in Python
Control Structures in PythonControl Structures in Python
Control Structures in PythonSumit Satam
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programmingSrinivas Narasegouda
 
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...Edureka!
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]vikram mahendra
 

What's hot (20)

Python If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | EdurekaPython If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | Edureka
 
Python Decision Making
Python Decision MakingPython Decision Making
Python Decision Making
 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
 
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAChapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Python strings
Python stringsPython strings
Python strings
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
Data types in python
Data types in pythonData types in python
Data types in python
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
 
Control Structures in Python
Control Structures in PythonControl Structures in Python
Control Structures in Python
 
Control statements
Control statementsControl statements
Control statements
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Python programming
Python  programmingPython  programming
Python programming
 
Python for loop
Python for loopPython for loop
Python for loop
 
Python
PythonPython
Python
 
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
 
Strings in python
Strings in pythonStrings in python
Strings in python
 

Similar to Python flow control basics

Control structures pyhton
Control structures  pyhtonControl structures  pyhton
Control structures pyhtonPrakash Jayaraman
 
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdfconditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdfsdvdsvsdvsvds
 
Python Decision Making And Loops.pdf
Python Decision Making And Loops.pdfPython Decision Making And Loops.pdf
Python Decision Making And Loops.pdfNehaSpillai1
 
Unit - 2 CAP.pptx
Unit - 2 CAP.pptxUnit - 2 CAP.pptx
Unit - 2 CAP.pptxmalekaanjum1
 
control statements in python.pptx
control statements in python.pptxcontrol statements in python.pptx
control statements in python.pptxAnshu Varma
 
Chapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxChapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxXhelalSpahiu
 
python notes.pdf
python notes.pdfpython notes.pdf
python notes.pdfRohitSindhu10
 
controlstatementspy.docx
controlstatementspy.docxcontrolstatementspy.docx
controlstatementspy.docxmanohar25689
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docxJavvajiVenkat
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa Thapa
 
if else python.pdf
if else python.pdfif else python.pdf
if else python.pdfGshs6
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
Python programing
Python programingPython programing
Python programinghamzagame
 
Help with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelp with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelpmeinhomework
 

Similar to Python flow control basics (20)

Control structures pyhton
Control structures  pyhtonControl structures  pyhton
Control structures pyhton
 
loops.pdf
loops.pdfloops.pdf
loops.pdf
 
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdfconditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
 
Python Decision Making And Loops.pdf
Python Decision Making And Loops.pdfPython Decision Making And Loops.pdf
Python Decision Making And Loops.pdf
 
Unit - 2 CAP.pptx
Unit - 2 CAP.pptxUnit - 2 CAP.pptx
Unit - 2 CAP.pptx
 
control statements in python.pptx
control statements in python.pptxcontrol statements in python.pptx
control statements in python.pptx
 
Chapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxChapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptx
 
PRESENTATION.pptx
PRESENTATION.pptxPRESENTATION.pptx
PRESENTATION.pptx
 
pythonQuick.pdf
pythonQuick.pdfpythonQuick.pdf
pythonQuick.pdf
 
python notes.pdf
python notes.pdfpython notes.pdf
python notes.pdf
 
python 34💭.pdf
python 34💭.pdfpython 34💭.pdf
python 34💭.pdf
 
controlstatementspy.docx
controlstatementspy.docxcontrolstatementspy.docx
controlstatementspy.docx
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
 
Python for Beginners(v2)
Python for Beginners(v2)Python for Beginners(v2)
Python for Beginners(v2)
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptx
 
if else python.pdf
if else python.pdfif else python.pdf
if else python.pdf
 
Python session3
Python session3Python session3
Python session3
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Python programing
Python programingPython programing
Python programing
 
Help with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelp with Pyhon Programming Homework
Help with Pyhon Programming Homework
 

More from vikram mahendra

Communication skill
Communication skillCommunication skill
Communication skillvikram mahendra
 
Python Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemPython Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemvikram mahendra
 
Python Project on Computer Shop
Python Project on Computer ShopPython Project on Computer Shop
Python Project on Computer Shopvikram mahendra
 
PYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMPYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMvikram mahendra
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Pythonvikram mahendra
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONvikram mahendra
 
FLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONvikram mahendra
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1vikram mahendra
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2vikram mahendra
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2vikram mahendra
 
DATA TYPE IN PYTHON
DATA TYPE IN PYTHONDATA TYPE IN PYTHON
DATA TYPE IN PYTHONvikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONvikram mahendra
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONvikram mahendra
 
Python Introduction
Python IntroductionPython Introduction
Python Introductionvikram mahendra
 
GREEN SKILL[PART-2]
GREEN SKILL[PART-2]GREEN SKILL[PART-2]
GREEN SKILL[PART-2]vikram mahendra
 
GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]vikram mahendra
 
Dictionary in python
Dictionary in pythonDictionary in python
Dictionary in pythonvikram mahendra
 
Entrepreneurial skills
Entrepreneurial skillsEntrepreneurial skills
Entrepreneurial skillsvikram mahendra
 

More from vikram mahendra (20)

Communication skill
Communication skillCommunication skill
Communication skill
 
Python Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemPython Project On Cosmetic Shop system
Python Project On Cosmetic Shop system
 
Python Project on Computer Shop
Python Project on Computer ShopPython Project on Computer Shop
Python Project on Computer Shop
 
PYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMPYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEM
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Python
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
 
FLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHON
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
 
DATA TYPE IN PYTHON
DATA TYPE IN PYTHONDATA TYPE IN PYTHON
DATA TYPE IN PYTHON
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHON
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
GREEN SKILL[PART-2]
GREEN SKILL[PART-2]GREEN SKILL[PART-2]
GREEN SKILL[PART-2]
 
GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]
 
Dictionary in python
Dictionary in pythonDictionary in python
Dictionary in python
 
Entrepreneurial skills
Entrepreneurial skillsEntrepreneurial skills
Entrepreneurial skills
 
Boolean logic
Boolean logicBoolean logic
Boolean logic
 

Recently uploaded

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
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
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
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
 
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
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
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
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
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
 
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
 

Recently uploaded (20)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
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
 
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
 
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 ...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
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...
 
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
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
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
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
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...
 
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
 

Python flow control basics

  • 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”)