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)
Ad

More Related Content

What's hot (20)

Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
Kamal Acharya
 
Python programming : Control statements
Python programming : Control statementsPython programming : Control statements
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
Binay Kumar Ray
 
Python Modules
Python ModulesPython Modules
Python Modules
Nitin Reddy Katkam
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
narmadhakin
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
Praveen M Jigajinni
 
Python for Beginners(v3)
Python for Beginners(v3)Python for Beginners(v3)
Python for Beginners(v3)
Panimalar Engineering College
 
Python
PythonPython
Python
Aashish Jain
 
Python - object oriented
Python - object orientedPython - object oriented
Python - object oriented
Learnbay Datascience
 
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
 
Control structures i
Control structures i Control structures i
Control structures i
Ahmad Idrees
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!
Fariz Darari
 
What is Socket Programming in Python | Edureka
What is Socket Programming in Python | EdurekaWhat is Socket Programming in Python | Edureka
What is Socket Programming in Python | Edureka
Edureka!
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHON
vikram mahendra
 
Introduction to Python programming Language
Introduction to Python programming LanguageIntroduction to Python programming Language
Introduction to Python programming Language
MansiSuthar3
 
Polymorphism in Python
Polymorphism in Python Polymorphism in Python
Polymorphism in Python
Home
 
Python – Object Oriented Programming
Python – Object Oriented Programming Python – Object Oriented Programming
Python – Object Oriented Programming
Raghunath A
 
C program language tutorial pattern printing
C program language tutorial pattern printingC program language tutorial pattern printing
C program language tutorial pattern printing
Sourav Ganguly
 
Java Networking
Java NetworkingJava Networking
Java Networking
Sunil OS
 
Introduction to Python Programming language.pptx
Introduction to Python Programming language.pptxIntroduction to Python Programming language.pptx
Introduction to Python Programming language.pptx
BharathYusha1
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
narmadhakin
 
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
 
Control structures i
Control structures i Control structures i
Control structures i
Ahmad Idrees
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!
Fariz Darari
 
What is Socket Programming in Python | Edureka
What is Socket Programming in Python | EdurekaWhat is Socket Programming in Python | Edureka
What is Socket Programming in Python | Edureka
Edureka!
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHON
vikram mahendra
 
Introduction to Python programming Language
Introduction to Python programming LanguageIntroduction to Python programming Language
Introduction to Python programming Language
MansiSuthar3
 
Polymorphism in Python
Polymorphism in Python Polymorphism in Python
Polymorphism in Python
Home
 
Python – Object Oriented Programming
Python – Object Oriented Programming Python – Object Oriented Programming
Python – Object Oriented Programming
Raghunath A
 
C program language tutorial pattern printing
C program language tutorial pattern printingC program language tutorial pattern printing
C program language tutorial pattern printing
Sourav Ganguly
 
Java Networking
Java NetworkingJava Networking
Java Networking
Sunil OS
 
Introduction to Python Programming language.pptx
Introduction to Python Programming language.pptxIntroduction to Python Programming language.pptx
Introduction to Python Programming language.pptx
BharathYusha1
 

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

basics of optimizations presentation s
basics  of  optimizations presentation sbasics  of  optimizations presentation s
basics of optimizations presentation s
AnkitKumarSharma26
 
Python Course Lecture Defining Functions
Python Course Lecture Defining FunctionsPython Course Lecture Defining Functions
Python Course Lecture Defining Functions
MuhammadIfitikhar
 
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
 
Introduction to Python Prog. - Lecture 2
Introduction to Python Prog. - Lecture 2Introduction to Python Prog. - Lecture 2
Introduction to Python Prog. - Lecture 2
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
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
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
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
 
UNIT – 3.pptx for first year engineering
UNIT – 3.pptx for first year engineeringUNIT – 3.pptx for first year engineering
UNIT – 3.pptx for first year engineering
SabarigiriVason
 
Loops Branches and control flow in MATLAB
Loops Branches and control flow in MATLABLoops Branches and control flow in MATLAB
Loops Branches and control flow in MATLAB
Sufi Yasir Raza
 
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
 
basics of optimizations presentation s
basics  of  optimizations presentation sbasics  of  optimizations presentation s
basics of optimizations presentation s
AnkitKumarSharma26
 
Python Course Lecture Defining Functions
Python Course Lecture Defining FunctionsPython Course Lecture Defining Functions
Python Course Lecture Defining Functions
MuhammadIfitikhar
 
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
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statements
Intro C# Book
 
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
 
UNIT – 3.pptx for first year engineering
UNIT – 3.pptx for first year engineeringUNIT – 3.pptx for first year engineering
UNIT – 3.pptx for first year engineering
SabarigiriVason
 
Loops Branches and control flow in MATLAB
Loops Branches and control flow in MATLABLoops Branches and control flow in MATLAB
Loops Branches and control flow in MATLAB
Sufi Yasir Raza
 
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
 
Ad

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 |
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
 
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
 
Ad

Recently uploaded (20)

Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 

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)