XI- CONDITIONAL AND LOOPING CONSTRUCTS
XI- CONDITIONAL AND LOOPING CONSTRUCTS
Class : XI (2024-25)
ShriKant Yadav
PGT (Info. Pract.)
Chapter : 4
Conditional and Looping
Constructs
Introduction
• Generally a program executes from starting point to
end point.
• Some program does not execute in order.
• As per the requirement, execution order of the
program can be changed and it is also possible to
execute a program repeatedly.
• Python provides control structures to manage the
order of execution of a program, which are if-else,
for, while and jump statements like break, continue.
Types of statements
• In Python, statements are of 3 types-
» Empty Statements
• pass
» Simple Statements (Single Statement)
• name=input (“Enter your Name “)
• print(name) etc.
» Compound Statements
• <Compound Statement Header>:
<Indented Body containing multiple simple
statements/compound statements>
• Here, Header line starts with the keyword and ends at colon
(:).
• The body consists of more than one simple Python
statements or compound statements.
Statement Flow Control
• In a program, statements executes in sequential
manner or in selective manner or in iterative
manner.
Sequential Selective Iterative
Program Logic Development Tool
A program has following development stages-
1. Identification of the problem
2. Analysis of problem
3. Writing Algorithm or Designing Flowchart
4. Writing Code
5. Testing and Debugging
6. Implementation
7. Maintenance
Algorithm
• A process or set of rules to be followed in problem-
solving operations is an algorithm.
For ex-
Algorithm to add two numbers is as under-
1. Input First Number
2. Input Second Number
3. Add First Number with Second Number and store into
Third number.
4. Display Third number
Flowcharts
• A flowchart is a graphical representation of an algorithm,
workflow or process. The flowchart shows the steps as boxes of
various kinds, and their order by connecting the boxes with
arrows.
For ex- flowchart to calculate simple interest is as under-
Symbols to be
used in
Flowchart
if Statement
• In Python, if statement is used to select statement
for processing. If execution of a statement is to be
done on the basis of a condition, if statement is to
be used. Its syntax is-
if <condition>:
statement(s)
like -
if-else Statement
• If out of two statements, it is required to select one
statement for processing on the basis of a condition,
if-else statement is to be used. Its syntax is-
if <condition>:
statement(s) when condition is true
else:
statement(s) when condition is false
like -
if-elif Statements
• If out of multiple statements, it is required to select
one statement for processing on the basis of a
condition, if-elif statement is to be used. Its syntax
is-
if <condition1>: like -
statement(s) when condition1 is true
elif <condition2>:
statement(s) when condition2 is true
elif <condition3>:
statement(s) when condition3 is true
else
Nested If -else
– not in operator-
5 not in [1,2,3,4] will return True.
Table of a number by For loop
While <LogicalExpression>:
<loop body with increment Output
or decrement>
Start
Stop
Step
Jump Statements
break Statement
Output Output
Jump Statements
Continue Statement
Outputofboththe
programs
Nested Loop
OUTPUT
Assignments
1. WAP to find greatest among three numbers.
2. WAP to print the result on the basis of marks
entered of a student.
3. WAP to print counting up to n.
4. WAP to print even numbers up to n.
5. WAP to print odd numbers up to n.
6. WAP to print Fibonacci series.
7. WAP to calculate xn.
8. WAP to print different patterns.