SlideShare a Scribd company logo
Python Flow Control
if…else
for Loop
while loop
Break and continue
Pass statement
if...else
 Decision making is required when we want to
execute a code only if a certain condition is satisfied.
 The if…elif…else statement is used in Python for
decision making.
 In Python, the body of the if statement is indicated by
the indentation.
 Body starts with an indentation and the first
unindented line marks the end.
 Python interprets non-zero values
asTrue. None and 0 are interpreted as False.
Python Flow Control
Exercise – if
 Write a program to give a discount of
10% if the total bill amount exceeds 1000.
Python Flow Control
if...else Statement
 The if..else statement evaluates test expression and will
execute body of if only when test condition is True.
 If the condition is False, body of else is executed.
Indentation is used to separate the blocks.
Python Flow Control
Exercise
 Write a program to check if a given
number is a multiple of 5.
if...elif...else
 The elif is short for else if. It allows us
to check for multiple expressions.
 If the condition for if is False, it checks
the condition of the next elif block
and so on.
 If all the conditions are False, body of
else is executed.
 Only one block among the
several if...elif...else blocks is executed
according to the condition.
 The if block can have only
one else block. But it can have
multiple elifblocks.
Python Flow Control
Python Flow Control
Programming Task
 Minimum age to Cast yourVote : 18
 Minimum age to Contest an Election: 25
 Given the age verify if the person can
vote and can s(he) contest an election.
Exercise
 Write a program to check if a given year is leap year or not.
 Logic:
 if a year is not divisible by 4, its not a leap year.
 If a year is divisible by 4 and not divisible by 100, it’s a leap year.
 If a year is divisible by 4 and 100 then it should be divisible by 400
to be a leap year
Python Flow Control
Python Flow Control
Python Flow Control
Loops
 Loops are used in programming to
repeat a specific block of code.
 Looping Constructs in Python
◦ while
◦ for
While loop
 The while loop in Python is used to iterate over
a block of code as long as the test expression
(condition) is true.
 We generally use this loop when we don't know
beforehand, the number of times to iterate.
Python Flow Control
 Write a program to print the number of
digits of a given number using while loop.
Python Flow Control
For loop
 For loops iterate over a given sequence.
 Here, val is the variable that takes the value of the item
inside the sequence on each iteration.
 Loop continues until we reach the last item in the
sequence.The body of for loop is separated from the
rest of the code using indentation.
Python Flow Control
Range Function
 We can generate a sequence of numbers
using range() function.
 range(10) will generate numbers from 0 to 9 (10
numbers).
 To force this function to output all the items, we can
use the function list().
Range function
 We can also define the start, stop and
step size as range(start,stop,step size).
 step size defaults to 1 if not provided.
Python Flow Control
Exercise
 Write a program to calculate the factorial
of a given number.
Python Flow Control
Python Flow Control
break and continue
 Loops iterate over a block of code until test expression
is false, but sometimes we wish to terminate the
current iteration or even the whole loop without
checking test expression.
 break statement
 The break statement terminates the loop containing it.
Control of the program flows to the statement
immediately after the body of the loop.
 If break statement is inside a nested loop (loop inside
another loop), break will terminate the innermost loop.
Python Flow Control
Exercise
 Write a program to check if a given
number is prime or not.
 If a number is divisible by any number
between 2 and n-1, its not prime,
otherwise prime
Python Flow Control
continue statement
 The continue statement is used to skip the rest of the
code inside a loop for the current iteration only. Loop
does not terminate but continues on with the next
iteration.
for loop with else
 A for loop can have an optional else block as well.
The else part is executed if the items in the sequence
used in for loop exhausts.
 break statement can be used to stop a for loop. In such
case, the else part is ignored.
 Hence, a for loop's else part runs if no break occurs.
for loop with else
Nested Loop
while loop with else
 Same as that of for loop, we can have an
optional else block with while loop as well.
Pass statement
 Suppose we have a loop or a function that is not
implemented yet, but we want to implement it in the
future.
 They cannot have an empty body.
 We use the pass statement to construct a body that
does nothing.
Ad

More Related Content

What's hot (20)

Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
Mohammed Sikander
 
Strings in python
Strings in pythonStrings in python
Strings in python
Prabhakaran V M
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
Megha V
 
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
PriyankaC44
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Python file handling
Python file handlingPython file handling
Python file handling
Prof. Dr. K. Adisesha
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
Abhilash Nair
 
PYTHON FEATURES.pptx
PYTHON FEATURES.pptxPYTHON FEATURES.pptx
PYTHON FEATURES.pptx
MaheShiva
 
Python tuple
Python   tuplePython   tuple
Python tuple
Mohammed Sikander
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
Mohammed Sikander
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
eShikshak
 
List in Python
List in PythonList in Python
List in Python
Siddique Ibrahim
 
Python programming : Control statements
Python programming : Control statementsPython programming : Control statements
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
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
Edureka!
 
Python for loop
Python for loopPython for loop
Python for loop
Aishwarya Deshmukh
 
Python Modules
Python ModulesPython Modules
Python Modules
Nitin Reddy Katkam
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
Devashish Kumar
 
Python Pandas
Python PandasPython Pandas
Python Pandas
Sunil OS
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
Pratik Devmurari
 
Python list
Python listPython list
Python list
Mohammed Sikander
 

Similar to Python Flow Control (20)

E-Notes_3721_Content_Document_20250107032537PM.pdf
E-Notes_3721_Content_Document_20250107032537PM.pdfE-Notes_3721_Content_Document_20250107032537PM.pdf
E-Notes_3721_Content_Document_20250107032537PM.pdf
aayushihirpara297
 
dizital pods session 5-loops.pptx
dizital pods session 5-loops.pptxdizital pods session 5-loops.pptx
dizital pods session 5-loops.pptx
VijayKumarLokanadam
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1
Devashish Kumar
 
Python basics Control flow chapter 3.pptx
Python basics Control flow chapter 3.pptxPython basics Control flow chapter 3.pptx
Python basics Control flow chapter 3.pptx
yeabtse1234
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
Syed Farjad Zia Zaidi
 
Programming in python - Week 4
Programming in python  - Week 4Programming in python  - Week 4
Programming in python - Week 4
Priya Nayak
 
Python session3
Python session3Python session3
Python session3
Aswin Krishnamoorthy
 
Lecture on Loop while loop for loop + program
Lecture on Loop while loop for loop + programLecture on Loop while loop for loop + program
Lecture on Loop while loop for loop + program
RahulKumar812056
 
Control Structures Python like conditions and loops
Control Structures Python like conditions and loopsControl Structures Python like conditions and loops
Control Structures Python like conditions and loops
ramireddyobulakondar
 
PYTHON FULL TUTORIAL WITH PROGRAMMS
PYTHON FULL TUTORIAL WITH PROGRAMMSPYTHON FULL TUTORIAL WITH PROGRAMMS
PYTHON FULL TUTORIAL WITH PROGRAMMS
Aniruddha Paul
 
PRESENTATION.pptx
PRESENTATION.pptxPRESENTATION.pptx
PRESENTATION.pptx
MahrAlyanYousafwasli
 
Control structures pyhton
Control structures  pyhtonControl structures  pyhton
Control structures pyhton
Prakash Jayaraman
 
Python Session - 4
Python Session - 4Python Session - 4
Python Session - 4
AnirudhaGaikwad4
 
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.pptppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
avishekpradhan24
 
pds first unit module 2 MODULE FOR ppt.pptx
pds first unit module 2 MODULE FOR ppt.pptxpds first unit module 2 MODULE FOR ppt.pptx
pds first unit module 2 MODULE FOR ppt.pptx
bmit1
 
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
 
break continue and pass statement in python.pptx
break continue and pass statement in python.pptxbreak continue and pass statement in python.pptx
break continue and pass statement in python.pptx
sayalee7
 
This is all about control flow in python intruducing the Break and Continue.pptx
This is all about control flow in python intruducing the Break and Continue.pptxThis is all about control flow in python intruducing the Break and Continue.pptx
This is all about control flow in python intruducing the Break and Continue.pptx
elezearrepil1
 
PPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.ppt
PPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.pptPPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.ppt
PPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.ppt
RahulKumar812056
 
Types of Statements in Python Programming Language
Types of Statements in Python Programming LanguageTypes of Statements in Python Programming Language
Types of Statements in Python Programming Language
Explore Skilled
 
E-Notes_3721_Content_Document_20250107032537PM.pdf
E-Notes_3721_Content_Document_20250107032537PM.pdfE-Notes_3721_Content_Document_20250107032537PM.pdf
E-Notes_3721_Content_Document_20250107032537PM.pdf
aayushihirpara297
 
dizital pods session 5-loops.pptx
dizital pods session 5-loops.pptxdizital pods session 5-loops.pptx
dizital pods session 5-loops.pptx
VijayKumarLokanadam
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1
Devashish Kumar
 
Python basics Control flow chapter 3.pptx
Python basics Control flow chapter 3.pptxPython basics Control flow chapter 3.pptx
Python basics Control flow chapter 3.pptx
yeabtse1234
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
Syed Farjad Zia Zaidi
 
Programming in python - Week 4
Programming in python  - Week 4Programming in python  - Week 4
Programming in python - Week 4
Priya Nayak
 
Lecture on Loop while loop for loop + program
Lecture on Loop while loop for loop + programLecture on Loop while loop for loop + program
Lecture on Loop while loop for loop + program
RahulKumar812056
 
Control Structures Python like conditions and loops
Control Structures Python like conditions and loopsControl Structures Python like conditions and loops
Control Structures Python like conditions and loops
ramireddyobulakondar
 
PYTHON FULL TUTORIAL WITH PROGRAMMS
PYTHON FULL TUTORIAL WITH PROGRAMMSPYTHON FULL TUTORIAL WITH PROGRAMMS
PYTHON FULL TUTORIAL WITH PROGRAMMS
Aniruddha Paul
 
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.pptppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
avishekpradhan24
 
pds first unit module 2 MODULE FOR ppt.pptx
pds first unit module 2 MODULE FOR ppt.pptxpds first unit module 2 MODULE FOR ppt.pptx
pds first unit module 2 MODULE FOR ppt.pptx
bmit1
 
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
 
break continue and pass statement in python.pptx
break continue and pass statement in python.pptxbreak continue and pass statement in python.pptx
break continue and pass statement in python.pptx
sayalee7
 
This is all about control flow in python intruducing the Break and Continue.pptx
This is all about control flow in python intruducing the Break and Continue.pptxThis is all about control flow in python intruducing the Break and Continue.pptx
This is all about control flow in python intruducing the Break and Continue.pptx
elezearrepil1
 
PPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.ppt
PPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.pptPPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.ppt
PPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.ppt
RahulKumar812056
 
Types of Statements in Python Programming Language
Types of Statements in Python Programming LanguageTypes of Statements in Python Programming Language
Types of Statements in Python Programming Language
Explore Skilled
 
Ad

More from Mohammed Sikander (20)

Strings in C - covers string functions
Strings in C - covers  string  functionsStrings in C - covers  string  functions
Strings in C - covers string functions
Mohammed Sikander
 
Smart Pointers, Modern Memory Management Techniques
Smart Pointers, Modern Memory Management TechniquesSmart Pointers, Modern Memory Management Techniques
Smart Pointers, Modern Memory Management Techniques
Mohammed Sikander
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Mohammed Sikander
 
Operator Overloading in C++
Operator Overloading in C++Operator Overloading in C++
Operator Overloading in C++
Mohammed Sikander
 
Python_Regular Expression
Python_Regular ExpressionPython_Regular Expression
Python_Regular Expression
Mohammed Sikander
 
Modern_CPP-Range-Based For Loop.pptx
Modern_CPP-Range-Based For Loop.pptxModern_CPP-Range-Based For Loop.pptx
Modern_CPP-Range-Based For Loop.pptx
Mohammed Sikander
 
Modern_cpp_auto.pdf
Modern_cpp_auto.pdfModern_cpp_auto.pdf
Modern_cpp_auto.pdf
Mohammed Sikander
 
Python dictionary
Python   dictionaryPython   dictionary
Python dictionary
Mohammed Sikander
 
Python strings
Python stringsPython strings
Python strings
Mohammed Sikander
 
Python set
Python setPython set
Python set
Mohammed Sikander
 
Pointer basics
Pointer basicsPointer basics
Pointer basics
Mohammed Sikander
 
Pipe
PipePipe
Pipe
Mohammed Sikander
 
Signal
SignalSignal
Signal
Mohammed Sikander
 
File management
File managementFile management
File management
Mohammed Sikander
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Mohammed Sikander
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - Reference
Mohammed Sikander
 
Java arrays
Java    arraysJava    arrays
Java arrays
Mohammed Sikander
 
Java strings
Java   stringsJava   strings
Java strings
Mohammed Sikander
 
Java notes 1 - operators control-flow
Java notes   1 - operators control-flowJava notes   1 - operators control-flow
Java notes 1 - operators control-flow
Mohammed Sikander
 
Ad

Recently uploaded (20)

Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 

Python Flow Control

  • 1. Python Flow Control if…else for Loop while loop Break and continue Pass statement
  • 2. if...else  Decision making is required when we want to execute a code only if a certain condition is satisfied.  The if…elif…else statement is used in Python for decision making.  In Python, the body of the if statement is indicated by the indentation.  Body starts with an indentation and the first unindented line marks the end.  Python interprets non-zero values asTrue. None and 0 are interpreted as False.
  • 4. Exercise – if  Write a program to give a discount of 10% if the total bill amount exceeds 1000.
  • 6. if...else Statement  The if..else statement evaluates test expression and will execute body of if only when test condition is True.  If the condition is False, body of else is executed. Indentation is used to separate the blocks.
  • 8. Exercise  Write a program to check if a given number is a multiple of 5.
  • 9. if...elif...else  The elif is short for else if. It allows us to check for multiple expressions.  If the condition for if is False, it checks the condition of the next elif block and so on.  If all the conditions are False, body of else is executed.  Only one block among the several if...elif...else blocks is executed according to the condition.  The if block can have only one else block. But it can have multiple elifblocks.
  • 12. Programming Task  Minimum age to Cast yourVote : 18  Minimum age to Contest an Election: 25  Given the age verify if the person can vote and can s(he) contest an election.
  • 13. Exercise  Write a program to check if a given year is leap year or not.  Logic:  if a year is not divisible by 4, its not a leap year.  If a year is divisible by 4 and not divisible by 100, it’s a leap year.  If a year is divisible by 4 and 100 then it should be divisible by 400 to be a leap year
  • 17. Loops  Loops are used in programming to repeat a specific block of code.  Looping Constructs in Python ◦ while ◦ for
  • 18. While loop  The while loop in Python is used to iterate over a block of code as long as the test expression (condition) is true.  We generally use this loop when we don't know beforehand, the number of times to iterate.
  • 20.  Write a program to print the number of digits of a given number using while loop.
  • 22. For loop  For loops iterate over a given sequence.  Here, val is the variable that takes the value of the item inside the sequence on each iteration.  Loop continues until we reach the last item in the sequence.The body of for loop is separated from the rest of the code using indentation.
  • 24. Range Function  We can generate a sequence of numbers using range() function.  range(10) will generate numbers from 0 to 9 (10 numbers).  To force this function to output all the items, we can use the function list().
  • 25. Range function  We can also define the start, stop and step size as range(start,stop,step size).  step size defaults to 1 if not provided.
  • 27. Exercise  Write a program to calculate the factorial of a given number.
  • 30. break and continue  Loops iterate over a block of code until test expression is false, but sometimes we wish to terminate the current iteration or even the whole loop without checking test expression.  break statement  The break statement terminates the loop containing it. Control of the program flows to the statement immediately after the body of the loop.  If break statement is inside a nested loop (loop inside another loop), break will terminate the innermost loop.
  • 32. Exercise  Write a program to check if a given number is prime or not.  If a number is divisible by any number between 2 and n-1, its not prime, otherwise prime
  • 34. continue statement  The continue statement is used to skip the rest of the code inside a loop for the current iteration only. Loop does not terminate but continues on with the next iteration.
  • 35. for loop with else  A for loop can have an optional else block as well. The else part is executed if the items in the sequence used in for loop exhausts.  break statement can be used to stop a for loop. In such case, the else part is ignored.  Hence, a for loop's else part runs if no break occurs.
  • 38. while loop with else  Same as that of for loop, we can have an optional else block with while loop as well.
  • 39. Pass statement  Suppose we have a loop or a function that is not implemented yet, but we want to implement it in the future.  They cannot have an empty body.  We use the pass statement to construct a body that does nothing.