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 conditional statement.pptx
PDF
Conditional operators
 
PPTX
AI_Session 3 Problem Solving Agent and searching for solutions.pptx
PPTX
Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control S...
PDF
Python Basics
PPT
មេរៀនៈ Data Structure and Algorithm in C/C++
PPTX
Switch case in C++
PPTX
Python Libraries and Modules
python conditional statement.pptx
Conditional operators
 
AI_Session 3 Problem Solving Agent and searching for solutions.pptx
Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control S...
Python Basics
មេរៀនៈ Data Structure and Algorithm in C/C++
Switch case in C++
Python Libraries and Modules

What's hot (20)

PPTX
Control structures in java
PPT
Bitwise operators
PPT
4.4 hashing
PPTX
Intermediate code- generation
PDF
Introduction to OpenMP
PPTX
Object oriented programming in python
PPTX
Python OOPs
PDF
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
PDF
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
PPTX
Introduction to AI Search problem .pptx
PDF
Python decision making
PPT
1.python interpreter and interactive mode
PPT
Design and Analysis of Algorithms
PPTX
Basics of Object Oriented Programming in Python
PPTX
Nested loops
PPTX
Python libraries
PPTX
Hash table in data structure and algorithm
PPTX
Control Strategies in AI
PPTX
Decision Making & Loops
PDF
AI local search
Control structures in java
Bitwise operators
4.4 hashing
Intermediate code- generation
Introduction to OpenMP
Object oriented programming in python
Python OOPs
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Introduction to AI Search problem .pptx
Python decision making
1.python interpreter and interactive mode
Design and Analysis of Algorithms
Basics of Object Oriented Programming in Python
Nested loops
Python libraries
Hash table in data structure and algorithm
Control Strategies in AI
Decision Making & Loops
AI local search
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
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Introduction and Scope of Bichemistry.pptx
PDF
Open folder Downloads.pdf yes yes ges yes
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Cardiovascular Pharmacology for pharmacy students.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
Open Quiz Monsoon Mind Game Final Set.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
Abdominal Access Techniques with Prof. Dr. R K Mishra
Introduction and Scope of Bichemistry.pptx
Open folder Downloads.pdf yes yes ges yes
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Week 4 Term 3 Study Techniques revisited.pptx
The Final Stretch: How to Release a Game and Not Die in the Process.
UPPER GASTRO INTESTINAL DISORDER.docx
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
O5-L3 Freight Transport Ops (International) V1.pdf

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)