CLASS -11 COMPUTER SCIENCE
CHAPTER-4 CONDITIONAL AND ITERATIVE STATEMENTS
🔔To download textbook pdf click on the ''DOWNLOAD'' button below -
NOTES FOR COMPLETE UNDERSTANDING -
- Usually a program executes from starting point to
end point but some does not execute in order.
- As required, execution order of the
program can be changed or executed repeatedly.
- Python consists a special control structure to see upon the
order of execution of a program, which are as follows : if-else,
for, while and jump statements like break, continue .
- In Python, statements are of 3 types- » Empty Statements • pass » Simple Statements (Single Statement) • name=input (“Enter your Name “) • print(name) etc. » Compound Statements
: • Here, Header line starts with the keyword and ends at colon
(:). • The body of compound statement has multiple simple Python
statements or compound statements.
Statement Flow Control :
- In a program , statements gets executed in queue like (sequential) or in selective or in iterative
manner. >Sequential >Selective >Iterative
A program has below 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:
An algorithm in a program is a set of rules to be followed in problem solving . For eg. 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 :
It is a graphical representation of an algorithm. It shows the steps enclosed in boxes of
various shapes like square , parallelogram, etc. and their order is shown by connecting the boxes with
arrows.
if Statement :
if statement is used to select statement
for processing in a program. If execution is done on the basis of a condition. Its syntax is- if <condition > : statement(s)
if-else Statement :
If out of two statements, it is required to select one
statement on the basis of a condition we use if-else statement. Its syntax is- if <condition> : statement 1 else: statement 2
if-elif Statements :
If out of multiple statements, it is required to select
one statement for processing on the basis of a
condition then we use it. Its syntax
is- if <condition> : statement 1 elif <condition> : statement 2 else <condition> : statement 3
Loop/ Iteration :
These control structures are used for continuous execution of statement(s) on the basis of a condition.
Loop has 3 main components 1. Start (initialization of loop) 2. Step (moving forward in loop ) 3. Stop (ending of loop)
Python has following loops- – for loop – while loop
range ( ) Function :
It is an important function . its
syntax is range ( ,)
If we write - range (0,15)
Then a list will be created with the values [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14] i.e. from
lower limit or the first number provided in ( ) upto the value one less than last limit. >range (0,10,2) will have the list [0,2,4,6,8]. >range (7,0,-1) will have the list [7,6,5,4,3,2,1].
in and not in operator-- 4 in [1,2,3,4] will return True. -- 35 in [1,2,3,4] will return False.
- not in operator -- 15 not in [1,2,3,4] will return True.
🔔MORE MATERIALS TO BE UPLOADED STAY TUNED🔔