Conditional and Iterative Statements in Python Class 11

Conditional and Iterative Statements in Python Class 11

conditional and iterative statements

conditional and iterative statements

Types of statements:- 

conditional and iterative statements

(1) empty statement:-

the simplest statement is empty statement i.e.,

statement which does nothing.in python an empty statement is pass statement in the flow of control.

pass

 

(2)simple statement:-

any single executable statement is a simple statement in python.for example, following is simple statement in python:

name = input(“your name”)

(3)compound statement:-

a compound statement represents a group of statements executed as a unit. the compound statement of python are written in a specific pattern as shown below:

<compound statement header>

<indented body containing multiple simple

and /or compound statement>

statement in flow of control:-

(1)sequence
(2)selection
(3)iteration(looping)

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.

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)

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

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

statement(s) when condition1 is true

elif <condition2>:

statement(s) when condition2 is true

elif <condition3>:

statement(s) when condition3 is true

else:

Loop/ Repetition/ Iteration:-

These control structures are used for repeated

execution of statement(s) on the basis of a condition.

Loop has 3 main components1. 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

• In Python, an important function is range( ). its

syntax isrange ( <lower limit>,<upper limit>)

If we write – range (0,5 )

Then a list will be created with the values [0,1,2,3,4] i.e. from

lower limit to the value one less than ending limit.

range (0,10,2) will have the list [0,2,4,6,8].

range (5,0,-1) will have the list [5,4,3,2,1].

in and not in operator:-

• in operator3 in [1,2,3,4] will return True.

5 in [1,2,3,4] will return False.

– not in operator5 not in [1,2,3,4] will return True.

Table of a number by For loop:

Syntax of For Loop

for <var> in <sequence>:

<statements to repeat>

num=int(input(“enter a number”)

for y in range(1,11):

print(num,”x”,y,”=”,num*y)

Table of a number by while loop:-

Syntax of While Loop

While <LogicalExpression>:

<loop body with increment

or decrement>

n=int(input(“enter a number”)

c=1

while c<11:

print(n,”x”,c,”=”,n*c)

c+=1

Jump Statements:-
break Statement

while <test-condition>:

statement1

if <condition>:

break

statement2

statement3

Statement4

statement5

Jump Statements

continue Statement

while <test-condition>:

statement1

if <condition>:

continue

statement2

statement3

Statement4

statement5

Read More :-

conditional and iterative statements important questions

conditional and iterative statements class 11 notes

Python Loops – For, While, Nested Loops With Examples

To Read in details :-

Understanding Python if-else Statement 2021

Python Loops – For, While, Nested Loops With Examples

Python Tutorial 2021