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

PPTX
Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control S...
PDF
Python Basics | Python Tutorial | Edureka
PPTX
Python for loop
PDF
Algorithms Lecture 2: Analysis of Algorithms I
PDF
Introduction to python programming
PDF
Python Class | Python Programming | Python Tutorial | Edureka
PPTX
Loops in C
Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control S...
Python Basics | Python Tutorial | Edureka
Python for loop
Algorithms Lecture 2: Analysis of Algorithms I
Introduction to python programming
Python Class | Python Programming | Python Tutorial | Edureka
Loops in C

What's hot (20)

PPTX
Python Functions
PPT
context free language
PPT
Introduction to Python
PDF
Linear Regression vs Logistic Regression | Edureka
PPTX
Asymptotic notations
PDF
Introduction To Python | Edureka
PDF
Python Decision Making And Loops.pdf
PPTX
Eclat algorithm in association rule mining
PDF
Network programming Using Python
PPT
Module4 lex and yacc.ppt
PPTX
Nlp toolkits and_preprocessing_techniques
PDF
Python unit 2 as per Anna university syllabus
PPTX
Introduction to python
PDF
Python programming : Files
PDF
Python Basics
PDF
Introduction to python
PPTX
python conditional statement.pptx
PPT
Ch 3 event driven programming
PPTX
STRINGS IN PYTHON
PPTX
Loops in Python
Python Functions
context free language
Introduction to Python
Linear Regression vs Logistic Regression | Edureka
Asymptotic notations
Introduction To Python | Edureka
Python Decision Making And Loops.pdf
Eclat algorithm in association rule mining
Network programming Using Python
Module4 lex and yacc.ppt
Nlp toolkits and_preprocessing_techniques
Python unit 2 as per Anna university syllabus
Introduction to python
Python programming : Files
Python Basics
Introduction to python
python conditional statement.pptx
Ch 3 event driven programming
STRINGS IN PYTHON
Loops in Python
Ad

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

PPT
basics of optimizations presentation s
PDF
Python Course Lecture Defining Functions
PDF
Sample Exam Questions on Python for revision
PPTX
Ch5 Selection Statements
PPTX
3 operators-expressions-and-statements-120712073351-phpapp01
PPTX
3 operators-expressions-and-statements-120712073351-phpapp01
PPTX
03. operators and-expressions
PDF
Python Unit 3 - Control Flow and Functions
PDF
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
PPTX
03. Operators Expressions and statements
PDF
14. Recursion.pdf
PPTX
Functional programming
PPTX
2.overview of c#
PDF
07 control+structures
PPTX
UNIT – 3.pptx for first year engineering
PPTX
Loops Branches and control flow in MATLAB
PDF
if statements in Python -A lecture class
PPTX
Conditional Statements.pptx
PPT
Control Statement.ppt
basics of optimizations presentation s
Python Course Lecture Defining Functions
Sample Exam Questions on Python for revision
Ch5 Selection Statements
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01
03. operators and-expressions
Python Unit 3 - Control Flow and Functions
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
03. Operators Expressions and statements
14. Recursion.pdf
Functional programming
2.overview of c#
07 control+structures
UNIT – 3.pptx for first year engineering
Loops Branches and control flow in MATLAB
if statements in Python -A lecture class
Conditional Statements.pptx
Control Statement.ppt
Ad

More from FabMinds (20)

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

Recently uploaded (20)

PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
Pre independence Education in Inndia.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
VCE English Exam - Section C Student Revision Booklet
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Pre independence Education in Inndia.pdf
Cell Types and Its function , kingdom of life
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Basic Mud Logging Guide for educational purpose
Week 4 Term 3 Study Techniques revisited.pptx
Anesthesia in Laparoscopic Surgery in India
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Renaissance Architecture: A Journey from Faith to Humanism
Supply Chain Operations Speaking Notes -ICLT Program
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Module 4: Burden of Disease Tutorial Slides S2 2025
2.FourierTransform-ShortQuestionswithAnswers.pdf
Insiders guide to clinical Medicine.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student

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)