SlideShare a Scribd company logo
Python Programming
Unit – II (Part II)
(Lecture 11)
Conditionals and Recursion
Recursion Infinite Recursion Keyboard input
Python Programming
Unit – II (Part II)
(Lecture 9)
Conditionals and Recursion
Syllabus
Lecture 9
Lecture 10
Lecture 11
Floor division and
modulus
Boolean expressions
Logical operators
Conditional
execution
Alternative
execution
Chained
conditionals
Nested
conditionals
Recursion
Infinite Recursion
Keyboard input
Syllabus
Lecture 9
Floor division and
modulus
Boolean expressions
Logical operators
• There are three logical
operators:
1. and
2. or
3. not
Relational operators:
• A = = B(Equal to)
• A! = B (Not equal to)
• A > B (Greater than)
• A < B (Less than)
• A > = B (Greater than or equal to)
• A < = B (Less than or equal to)
A Boolean expression is either
true or false.
• Ex: A = 5, B = 5, C = 6
• A = = B returns True
• A = = C returns False
Floor division:
• Digits after the decimal point
are removed.
• Symbol for Floor division: //
• Ex: 9 / 2 is 4.5 (Division)
9 // 2 is 4 (Floor division)
Modulus:
• Returns the remainder value
• Symbol for Modulus: %
• Ex: 9 % 2 is 1
Floor division and
modulus
Boolean expressions Logical operators
• There are three logical
operators:
1. and
2. or
3. not
Relational operators:
• A = = B(Equal to)
• A! = B (Not equal to)
• A > B (Greater than)
• A < B (Less than)
• A > = B (Greater than or equal to)
• A < = B (Less than or equal to)
A Boolean expression is either
true or false.
• Ex: A = 5, B = 5, C = 6
• A = = B returns True
• A = = C returns False
Floor division:
• Digits after the decimal point
are removed.
• Symbol for Floor division: //
• Ex: 9 / 2 is 4.5 (Division)
9 // 2 is 4 (Floor division)
Modulus:
• Returns the remainder value
• Symbol for Modulus: %
• Ex: 9 % 2 is 1
Floor division and
modulus
Boolean expressions Logical operators
Python Programming
Unit – II (Part II)
(Lecture 10)
Conditionals and Recursion
Syllabus
Lecture 9
Lecture 10
Lecture 11
Floor division and
modulus
Boolean expressions
Logical operators
Conditional
execution
Alternative
execution
Chained
conditionals
Nested
conditionals
Recursion
Infinite Recursion
Keyboard input
Syllabus
Lecture 10
Conditional
execution
Alternative
execution
Chained
conditionals
Nested
conditionals
Conditional
execution
Alternative
execution
Chained
conditionals
Nested
conditionals
• Conditions change
the flow of program
execution
• if statement is used
in conditions
Syntax:
if condition:
statement 1
…
• Two possibilities
(else is used)
Syntax:
if condition:
statement 1
…
else:
statement 2
…
• More than two
possibilities.
• elif is used.
Syntax:
if condition:
statement 1
elif condition:
statement 2
elif condition:
statement 3
else:
statement 4
• Another Condition
in one condition
Syntax:
if condition1:
if condition2:
statement 1
else:
statement 2
else:
statement 3
Conditionals
Conditional
execution
Alternative
execution
Chained
conditionals
Nested
conditionals
• Conditions change
the flow of program
execution
• if statement is used
in conditions
Syntax:
if condition:
statement 1
…
• Two possibilities
(else is used)
Syntax:
if condition:
statement 1
…
else:
statement 2
…
• More than two
possibilities.
• elif is used.
Syntax:
if condition:
statement 1
elif condition:
statement 2
elif condition:
statement 3
else:
statement 4
• Another Condition
in one condition
Syntax:
if condition1:
if condition2:
statement 1
else:
statement 2
else:
statement 3
Python Programming
Unit – II (Part II)
(Lecture 11)
Conditionals and Recursion
• There are three logical
operators:
1. and
2. or
3. not
Relational operators:
• A = = B(Equal to)
• A! = B (Not equal to)
• A > B (Greater than)
• A < B (Less than)
• A > = B (Greater than or equal to)
• A < = B (Less than or equal to)
A Boolean expression is either
true or false.
• Ex: A = 5, B = 5, C = 6
• A = = B returns True
• A = = C returns False
Floor division:
• Digits after the decimal point
are removed.
• Symbol for Floor division: //
• Ex: 9 / 2 is 4.5 (Division)
9 // 2 is 4 (Floor division)
Modulus:
• Returns the remainder value
• Symbol for Modulus: %
• Ex: 9 % 2 is 1
Floor division and
modulus
Boolean expressions Logical operators
Conditional
execution
Alternative
execution
Chained
conditionals
Nested
conditionals
• Conditions change
the flow of program
execution
• if statement is used
in conditions
Syntax:
if condition:
statement 1
…
• Two possibilities
(else is used)
Syntax:
if condition:
statement 1
…
else:
statement 2
…
• More than two
possibilities.
• elif is used.
Syntax:
if condition:
statement 1
elif condition:
statement 2
elif condition:
statement 3
else:
statement 4
• Another Condition
in one condition
Syntax:
if condition1:
if condition2:
statement 1
else:
statement 2
else:
statement 3
Syllabus
Lecture 9
Lecture 10
Lecture 11
Floor division and
modulus
Boolean expressions
Logical operators
Conditional
execution
Alternative
execution
Chained
conditionals
Nested
conditionals
Recursion
Infinite Recursion
Keyboard input
Lecture 11
Recursion
Infinite Recursion
Keyboard input
Recursion
Recursion
• Function to call
itself
Ex:
def countdown(n):
if n < 0:
print (“Blast”)
else:
print (n)
n = n - 1
countdown(n)
Countdown(n)
n
4
If
n < 0
False
Print(n)
n = n-1
Output:
4
Recursion
• Function to call
itself
Ex:
def countdown(n):
if n < 0:
print (“Blast”)
else:
print (n)
n = n - 1
countdown(n)
Countdown(n)
n
3
If
n < 0
False
Print(n)
n = n-1
Call count down
Output:
4
3
Recursion
• Function to call
itself
Ex:
def countdown(n):
if n < 0:
print (“Blast”)
else:
print (n)
n = n - 1
countdown(n)
Countdown(n)
n
2
If
n < 0
False
Print(n)
n = n-1
Call count down
Output:
4
3
2
Recursion
• Function to call
itself
Ex:
def countdown(n):
if n < 0:
print (“Blast”)
else:
print (n)
n = n - 1
countdown(n)
Countdown(n)
n
1
If
n < 0
False
Print(n)
n = n-1
Call count down
Output:
4
3
2
1
Recursion
• Function to call
itself
Ex:
def countdown(n):
if n < 0:
print (“Blast”)
else:
print (n)
n = n - 1
countdown(n)
Countdown(n)
n
0
If
n < 0
False
Print(n)
n = n-1
Call count down
Output:
4
3
2
1
0
Recursion
• Function to call
itself
Ex:
def countdown(n):
if n < 0:
print (“Blast”)
else:
print (n)
n = n - 1
countdown(n)
Countdown(n)
n
-1
If
n < 0
False
Print(n)
n = n-1
Call count down
Output:
4
3
2
1
0
Blast
Print(“Blast”)
True
Recursion
Lecture 11
Recursion
Infinite Recursion
Keyboard input
Countdown(n)
n
4
If
n < 0
False
Print(n)
n = n+1
Output:
4
Infinite Recursion
• Making recursive
calls forever
• The program never
terminates.
Ex:
def countdown(n):
if n < 0:
print (“Blast”)
else:
print (n)
n=n+1
countdown(n)
Countdown(n)
n
5
If
n < 0
False
Print(n)
n = n+1
Call count down
Output:
4
5
Infinite Recursion
• Making recursive
calls forever
• The program never
terminates.
Ex:
def countdown(n):
if n < 0:
print (“Blast”)
else:
print (n)
countdown(n+1)
Countdown(n)
n
6
If
n < 0
False
Print(n)
n = n+1
Call count down
Output:
4
5
6
Infinite Recursion
• Making recursive
calls forever
• The program never
terminates.
Ex:
def countdown(n):
if n < 0:
print (“Blast”)
else:
print (n)
countdown(n+1)
Countdown(n)
n
7
If
n < 0
False
Print(n)
n = n+1
Call count down
Output:
4
5
6
7
Infinite Recursion
• Making recursive
calls forever
• The program never
terminates.
Ex:
def countdown(n):
if n < 0:
print (“Blast”)
else:
print (n)
countdown(n+1)
Countdown(n)
n
8
If
n < 0
False
Print(n)
n = n+1
Call count down
Output:
4
5
6
7
8
Infinite Recursion
• Making recursive
calls forever
• The program never
terminates.
Ex:
def countdown(n):
if n < 0:
print (“Blast”)
else:
print (n)
countdown(n+1)
Countdown(n)
n
9
If
n < 0
False
Print(n)
n = n+1
Call count down
Output:
4
5
6
7
8
Infinite recursion
Infinite Recursion
• Making recursive
calls forever
• The program never
terminates.
Ex:
def countdown(n):
if n < 0:
print (“Blast”)
else:
print (n)
countdown(n+1)
Recursion
Lecture 11
Recursion
Infinite Recursion
Keyboard input
Keyboard input
• Accept input
from the user
with keyboard.
• input function
is used
A = 5
B = 6
print( A + B ) is 11
Here A & B variables has fixed values (given in
the program)
A = int(input("enter a value:"))
B = int(input("enter b value:"))
print( A + B)
Here A & B variables has no fixed values (given
in runtime)

More Related Content

What's hot

functions of C++
functions of C++functions of C++
functions of C++
tarandeep_kaur
 
Python-Tuples
Python-TuplesPython-Tuples
Python-Tuples
Krishna Nanda
 
NUMPY
NUMPY NUMPY
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
Anusuya123
 
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!
 
Python - the basics
Python - the basicsPython - the basics
Python - the basics
University of Technology
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
hydpy
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
Senthil Kumar
 
Python sqlite3
Python sqlite3Python sqlite3
Python sqlite3
Alexey Bovanenko
 
Python unit 3 and Unit 4
Python unit 3 and Unit 4Python unit 3 and Unit 4
Python unit 3 and Unit 4
Anandh Arumugakan
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
Akhil Kaushik
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
Simplilearn
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
Kamal Acharya
 
Functions in python
Functions in pythonFunctions in python
Functions in python
colorsof
 
Lists
ListsLists
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
Mohd Arif
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
Gerwin Ocsena
 
Modular programming
Modular programmingModular programming
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
Meghaj Mallick
 

What's hot (20)

functions of C++
functions of C++functions of C++
functions of C++
 
Python-Tuples
Python-TuplesPython-Tuples
Python-Tuples
 
NUMPY
NUMPY NUMPY
NUMPY
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
 
Operators in Python
Operators in PythonOperators in Python
Operators in 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...
 
Python - the basics
Python - the basicsPython - the basics
Python - the basics
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Python sqlite3
Python sqlite3Python sqlite3
Python sqlite3
 
Python unit 3 and Unit 4
Python unit 3 and Unit 4Python unit 3 and Unit 4
Python unit 3 and Unit 4
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
Lists
ListsLists
Lists
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 
Modular programming
Modular programmingModular programming
Modular programming
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
 

Similar to Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |

Sample Exam Questions on Python for revision
Sample Exam Questions on Python for revisionSample Exam Questions on Python for revision
Sample Exam Questions on Python for revision
afsheenfaiq2
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection Statements
SzeChingChen
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01
Abdul Samee
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01
Abdul Samee
 
03. operators and-expressions
03. operators and-expressions03. operators and-expressions
03. operators and-expressions
Stoian Kirov
 
Python Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and FunctionsPython Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and Functions
DhivyaSubramaniyam
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statements
Intro C# Book
 
14. Recursion.pdf
14. Recursion.pdf14. Recursion.pdf
14. Recursion.pdf
VivekBhimajiyani
 
Functional programming
Functional programmingFunctional programming
Functional programming
Prashant Kalkar
 
2.overview of c#
2.overview of c#2.overview of c#
2.overview of c#
Raghu nath
 
07 control+structures
07 control+structures07 control+structures
07 control+structures
baran19901990
 
if statements in Python -A lecture class
if statements in Python -A lecture classif statements in Python -A lecture class
if statements in Python -A lecture class
binzbinz3
 
Conditional Statements.pptx
Conditional Statements.pptxConditional Statements.pptx
Conditional Statements.pptx
Gautam623648
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.ppt
sanjay
 
Py-Slides-2.ppt
Py-Slides-2.pptPy-Slides-2.ppt
Py-Slides-2.ppt
AllanGuevarra1
 
Py-Slides-2 (1).ppt
Py-Slides-2 (1).pptPy-Slides-2 (1).ppt
Py-Slides-2 (1).ppt
KalaiVani395886
 
Py-Slides-2.ppt
Py-Slides-2.pptPy-Slides-2.ppt
Py-Slides-2.ppt
TejaValmiki
 
1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx
MOHAMMAD SAYDUL ALAM
 
Code optimization
Code optimizationCode optimization
Code optimization
veena venugopal
 
Code optimization
Code optimizationCode optimization
Code optimization
veena venugopal
 

Similar to Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion | (20)

Sample Exam Questions on Python for revision
Sample Exam Questions on Python for revisionSample Exam Questions on Python for revision
Sample Exam Questions on Python for revision
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection Statements
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01
 
03. operators and-expressions
03. operators and-expressions03. operators and-expressions
03. operators and-expressions
 
Python Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and FunctionsPython Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and Functions
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statements
 
14. Recursion.pdf
14. Recursion.pdf14. Recursion.pdf
14. Recursion.pdf
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
2.overview of c#
2.overview of c#2.overview of c#
2.overview of c#
 
07 control+structures
07 control+structures07 control+structures
07 control+structures
 
if statements in Python -A lecture class
if statements in Python -A lecture classif statements in Python -A lecture class
if statements in Python -A lecture class
 
Conditional Statements.pptx
Conditional Statements.pptxConditional Statements.pptx
Conditional Statements.pptx
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.ppt
 
Py-Slides-2.ppt
Py-Slides-2.pptPy-Slides-2.ppt
Py-Slides-2.ppt
 
Py-Slides-2 (1).ppt
Py-Slides-2 (1).pptPy-Slides-2 (1).ppt
Py-Slides-2 (1).ppt
 
Py-Slides-2.ppt
Py-Slides-2.pptPy-Slides-2.ppt
Py-Slides-2.ppt
 
1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Code optimization
Code optimizationCode optimization
Code optimization
 

More from FabMinds

Python Programming | JNTUA | UNIT 3 | Lists |
Python Programming | JNTUA | UNIT 3 | Lists | Python Programming | JNTUA | UNIT 3 | Lists |
Python Programming | JNTUA | UNIT 3 | Lists |
FabMinds
 
Python Programming | JNTUA | UNIT 3 | Strings |
Python Programming | JNTUA | UNIT 3 | Strings | Python Programming | JNTUA | UNIT 3 | Strings |
Python Programming | JNTUA | UNIT 3 | Strings |
FabMinds
 
Python Programming | JNTUA | UNIT 3 | Updating Variables & Iteration |
Python Programming | JNTUA | UNIT 3 | Updating Variables & Iteration | Python Programming | JNTUA | UNIT 3 | Updating Variables & Iteration |
Python Programming | JNTUA | UNIT 3 | Updating Variables & Iteration |
FabMinds
 
Python Programming | JNTUA | UNIT 2 | Case Study |
Python Programming | JNTUA | UNIT 2 | Case Study | Python Programming | JNTUA | UNIT 2 | Case Study |
Python Programming | JNTUA | UNIT 2 | Case Study |
FabMinds
 
Python Programming | JNTUA | UNIT 2 | Fruitful Functions |
Python Programming | JNTUA | UNIT 2 | Fruitful Functions | Python Programming | JNTUA | UNIT 2 | Fruitful Functions |
Python Programming | JNTUA | UNIT 2 | Fruitful Functions |
FabMinds
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocols
FabMinds
 
Internet connectivity
Internet connectivityInternet connectivity
Internet connectivity
FabMinds
 
Introduction for internet connectivity (IoT)
 Introduction for internet connectivity (IoT) Introduction for internet connectivity (IoT)
Introduction for internet connectivity (IoT)
FabMinds
 
web connectivity in IoT
web connectivity in IoTweb connectivity in IoT
web connectivity in IoT
FabMinds
 
message communication protocols in IoT
message communication protocols in IoTmessage communication protocols in IoT
message communication protocols in IoT
FabMinds
 
web communication protocols in IoT
web communication protocols in IoTweb communication protocols in IoT
web communication protocols in IoT
FabMinds
 
introduction for web connectivity (IoT)
introduction for web connectivity (IoT)introduction for web connectivity (IoT)
introduction for web connectivity (IoT)
FabMinds
 
Python Introduction | JNTUA | R19 | UNIT 1 | Functions
Python Introduction | JNTUA | R19 | UNIT 1 | FunctionsPython Introduction | JNTUA | R19 | UNIT 1 | Functions
Python Introduction | JNTUA | R19 | UNIT 1 | Functions
FabMinds
 
Python Introduction | JNTUA | R19 | UNIT 1 | Functions
Python Introduction | JNTUA | R19 | UNIT 1 | FunctionsPython Introduction | JNTUA | R19 | UNIT 1 | Functions
Python Introduction | JNTUA | R19 | UNIT 1 | Functions
FabMinds
 
Data enrichment
Data enrichmentData enrichment
Data enrichment
FabMinds
 
Communication technologies
Communication technologiesCommunication technologies
Communication technologies
FabMinds
 
M2M systems layers and designs standardizations
M2M systems layers and designs standardizationsM2M systems layers and designs standardizations
M2M systems layers and designs standardizations
FabMinds
 
Business models for business processes on IoT
Business models for business processes on IoTBusiness models for business processes on IoT
Business models for business processes on IoT
FabMinds
 
Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5
FabMinds
 
Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4
FabMinds
 

More from FabMinds (20)

Python Programming | JNTUA | UNIT 3 | Lists |
Python Programming | JNTUA | UNIT 3 | Lists | Python Programming | JNTUA | UNIT 3 | Lists |
Python Programming | JNTUA | UNIT 3 | Lists |
 
Python Programming | JNTUA | UNIT 3 | Strings |
Python Programming | JNTUA | UNIT 3 | Strings | Python Programming | JNTUA | UNIT 3 | Strings |
Python Programming | JNTUA | UNIT 3 | Strings |
 
Python Programming | JNTUA | UNIT 3 | Updating Variables & Iteration |
Python Programming | JNTUA | UNIT 3 | Updating Variables & Iteration | Python Programming | JNTUA | UNIT 3 | Updating Variables & Iteration |
Python Programming | JNTUA | UNIT 3 | Updating Variables & Iteration |
 
Python Programming | JNTUA | UNIT 2 | Case Study |
Python Programming | JNTUA | UNIT 2 | Case Study | Python Programming | JNTUA | UNIT 2 | Case Study |
Python Programming | JNTUA | UNIT 2 | Case Study |
 
Python Programming | JNTUA | UNIT 2 | Fruitful Functions |
Python Programming | JNTUA | UNIT 2 | Fruitful Functions | Python Programming | JNTUA | UNIT 2 | Fruitful Functions |
Python Programming | JNTUA | UNIT 2 | Fruitful Functions |
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocols
 
Internet connectivity
Internet connectivityInternet connectivity
Internet connectivity
 
Introduction for internet connectivity (IoT)
 Introduction for internet connectivity (IoT) Introduction for internet connectivity (IoT)
Introduction for internet connectivity (IoT)
 
web connectivity in IoT
web connectivity in IoTweb connectivity in IoT
web connectivity in IoT
 
message communication protocols in IoT
message communication protocols in IoTmessage communication protocols in IoT
message communication protocols in IoT
 
web communication protocols in IoT
web communication protocols in IoTweb communication protocols in IoT
web communication protocols in IoT
 
introduction for web connectivity (IoT)
introduction for web connectivity (IoT)introduction for web connectivity (IoT)
introduction for web connectivity (IoT)
 
Python Introduction | JNTUA | R19 | UNIT 1 | Functions
Python Introduction | JNTUA | R19 | UNIT 1 | FunctionsPython Introduction | JNTUA | R19 | UNIT 1 | Functions
Python Introduction | JNTUA | R19 | UNIT 1 | Functions
 
Python Introduction | JNTUA | R19 | UNIT 1 | Functions
Python Introduction | JNTUA | R19 | UNIT 1 | FunctionsPython Introduction | JNTUA | R19 | UNIT 1 | Functions
Python Introduction | JNTUA | R19 | UNIT 1 | Functions
 
Data enrichment
Data enrichmentData enrichment
Data enrichment
 
Communication technologies
Communication technologiesCommunication technologies
Communication technologies
 
M2M systems layers and designs standardizations
M2M systems layers and designs standardizationsM2M systems layers and designs standardizations
M2M systems layers and designs standardizations
 
Business models for business processes on IoT
Business models for business processes on IoTBusiness models for business processes on IoT
Business models for business processes on IoT
 
Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5
 
Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4
 

Recently uploaded

ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 

Recently uploaded (20)

ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 

Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |

  • 1. Python Programming Unit – II (Part II) (Lecture 11) Conditionals and Recursion Recursion Infinite Recursion Keyboard input
  • 2. Python Programming Unit – II (Part II) (Lecture 9) Conditionals and Recursion
  • 3. Syllabus Lecture 9 Lecture 10 Lecture 11 Floor division and modulus Boolean expressions Logical operators Conditional execution Alternative execution Chained conditionals Nested conditionals Recursion Infinite Recursion Keyboard input
  • 4. Syllabus Lecture 9 Floor division and modulus Boolean expressions Logical operators
  • 5. • There are three logical operators: 1. and 2. or 3. not Relational operators: • A = = B(Equal to) • A! = B (Not equal to) • A > B (Greater than) • A < B (Less than) • A > = B (Greater than or equal to) • A < = B (Less than or equal to) A Boolean expression is either true or false. • Ex: A = 5, B = 5, C = 6 • A = = B returns True • A = = C returns False Floor division: • Digits after the decimal point are removed. • Symbol for Floor division: // • Ex: 9 / 2 is 4.5 (Division) 9 // 2 is 4 (Floor division) Modulus: • Returns the remainder value • Symbol for Modulus: % • Ex: 9 % 2 is 1 Floor division and modulus Boolean expressions Logical operators
  • 6. • There are three logical operators: 1. and 2. or 3. not Relational operators: • A = = B(Equal to) • A! = B (Not equal to) • A > B (Greater than) • A < B (Less than) • A > = B (Greater than or equal to) • A < = B (Less than or equal to) A Boolean expression is either true or false. • Ex: A = 5, B = 5, C = 6 • A = = B returns True • A = = C returns False Floor division: • Digits after the decimal point are removed. • Symbol for Floor division: // • Ex: 9 / 2 is 4.5 (Division) 9 // 2 is 4 (Floor division) Modulus: • Returns the remainder value • Symbol for Modulus: % • Ex: 9 % 2 is 1 Floor division and modulus Boolean expressions Logical operators
  • 7. Python Programming Unit – II (Part II) (Lecture 10) Conditionals and Recursion
  • 8. Syllabus Lecture 9 Lecture 10 Lecture 11 Floor division and modulus Boolean expressions Logical operators Conditional execution Alternative execution Chained conditionals Nested conditionals Recursion Infinite Recursion Keyboard input
  • 10. Conditional execution Alternative execution Chained conditionals Nested conditionals • Conditions change the flow of program execution • if statement is used in conditions Syntax: if condition: statement 1 … • Two possibilities (else is used) Syntax: if condition: statement 1 … else: statement 2 … • More than two possibilities. • elif is used. Syntax: if condition: statement 1 elif condition: statement 2 elif condition: statement 3 else: statement 4 • Another Condition in one condition Syntax: if condition1: if condition2: statement 1 else: statement 2 else: statement 3 Conditionals
  • 11. Conditional execution Alternative execution Chained conditionals Nested conditionals • Conditions change the flow of program execution • if statement is used in conditions Syntax: if condition: statement 1 … • Two possibilities (else is used) Syntax: if condition: statement 1 … else: statement 2 … • More than two possibilities. • elif is used. Syntax: if condition: statement 1 elif condition: statement 2 elif condition: statement 3 else: statement 4 • Another Condition in one condition Syntax: if condition1: if condition2: statement 1 else: statement 2 else: statement 3
  • 12. Python Programming Unit – II (Part II) (Lecture 11) Conditionals and Recursion
  • 13. • There are three logical operators: 1. and 2. or 3. not Relational operators: • A = = B(Equal to) • A! = B (Not equal to) • A > B (Greater than) • A < B (Less than) • A > = B (Greater than or equal to) • A < = B (Less than or equal to) A Boolean expression is either true or false. • Ex: A = 5, B = 5, C = 6 • A = = B returns True • A = = C returns False Floor division: • Digits after the decimal point are removed. • Symbol for Floor division: // • Ex: 9 / 2 is 4.5 (Division) 9 // 2 is 4 (Floor division) Modulus: • Returns the remainder value • Symbol for Modulus: % • Ex: 9 % 2 is 1 Floor division and modulus Boolean expressions Logical operators
  • 14. Conditional execution Alternative execution Chained conditionals Nested conditionals • Conditions change the flow of program execution • if statement is used in conditions Syntax: if condition: statement 1 … • Two possibilities (else is used) Syntax: if condition: statement 1 … else: statement 2 … • More than two possibilities. • elif is used. Syntax: if condition: statement 1 elif condition: statement 2 elif condition: statement 3 else: statement 4 • Another Condition in one condition Syntax: if condition1: if condition2: statement 1 else: statement 2 else: statement 3
  • 15. Syllabus Lecture 9 Lecture 10 Lecture 11 Floor division and modulus Boolean expressions Logical operators Conditional execution Alternative execution Chained conditionals Nested conditionals Recursion Infinite Recursion Keyboard input
  • 17. Recursion • Function to call itself Ex: def countdown(n): if n < 0: print (“Blast”) else: print (n) n = n - 1 countdown(n) Countdown(n) n 4 If n < 0 False Print(n) n = n-1 Output: 4
  • 18. Recursion • Function to call itself Ex: def countdown(n): if n < 0: print (“Blast”) else: print (n) n = n - 1 countdown(n) Countdown(n) n 3 If n < 0 False Print(n) n = n-1 Call count down Output: 4 3
  • 19. Recursion • Function to call itself Ex: def countdown(n): if n < 0: print (“Blast”) else: print (n) n = n - 1 countdown(n) Countdown(n) n 2 If n < 0 False Print(n) n = n-1 Call count down Output: 4 3 2
  • 20. Recursion • Function to call itself Ex: def countdown(n): if n < 0: print (“Blast”) else: print (n) n = n - 1 countdown(n) Countdown(n) n 1 If n < 0 False Print(n) n = n-1 Call count down Output: 4 3 2 1
  • 21. Recursion • Function to call itself Ex: def countdown(n): if n < 0: print (“Blast”) else: print (n) n = n - 1 countdown(n) Countdown(n) n 0 If n < 0 False Print(n) n = n-1 Call count down Output: 4 3 2 1 0
  • 22. Recursion • Function to call itself Ex: def countdown(n): if n < 0: print (“Blast”) else: print (n) n = n - 1 countdown(n) Countdown(n) n -1 If n < 0 False Print(n) n = n-1 Call count down Output: 4 3 2 1 0 Blast Print(“Blast”) True
  • 24. Countdown(n) n 4 If n < 0 False Print(n) n = n+1 Output: 4 Infinite Recursion • Making recursive calls forever • The program never terminates. Ex: def countdown(n): if n < 0: print (“Blast”) else: print (n) n=n+1 countdown(n)
  • 25. Countdown(n) n 5 If n < 0 False Print(n) n = n+1 Call count down Output: 4 5 Infinite Recursion • Making recursive calls forever • The program never terminates. Ex: def countdown(n): if n < 0: print (“Blast”) else: print (n) countdown(n+1)
  • 26. Countdown(n) n 6 If n < 0 False Print(n) n = n+1 Call count down Output: 4 5 6 Infinite Recursion • Making recursive calls forever • The program never terminates. Ex: def countdown(n): if n < 0: print (“Blast”) else: print (n) countdown(n+1)
  • 27. Countdown(n) n 7 If n < 0 False Print(n) n = n+1 Call count down Output: 4 5 6 7 Infinite Recursion • Making recursive calls forever • The program never terminates. Ex: def countdown(n): if n < 0: print (“Blast”) else: print (n) countdown(n+1)
  • 28. Countdown(n) n 8 If n < 0 False Print(n) n = n+1 Call count down Output: 4 5 6 7 8 Infinite Recursion • Making recursive calls forever • The program never terminates. Ex: def countdown(n): if n < 0: print (“Blast”) else: print (n) countdown(n+1)
  • 29. Countdown(n) n 9 If n < 0 False Print(n) n = n+1 Call count down Output: 4 5 6 7 8 Infinite recursion Infinite Recursion • Making recursive calls forever • The program never terminates. Ex: def countdown(n): if n < 0: print (“Blast”) else: print (n) countdown(n+1)
  • 31. Keyboard input • Accept input from the user with keyboard. • input function is used A = 5 B = 6 print( A + B ) is 11 Here A & B variables has fixed values (given in the program) A = int(input("enter a value:")) B = int(input("enter b value:")) print( A + B) Here A & B variables has no fixed values (given in runtime)