Class 11 AI Chapter - Python Topic - Control Structure in Python - Arvindzeclass - NCERT Solutions

Post Top Ad

Thursday, February 20, 2025

Class 11 AI Chapter - Python Topic - Control Structure in Python


What are the different control structures in Python?

A control structure is a programming method which affects the flow of the execution of a program. Python provides different control structure to execute a program.

control statement in python
Control Statements in Python

1) Sequential Statement: The statement that executes in a sequential order. i.e. one after  the other without any jumps are called sequential statement. A sequential structure is also called a straight line path.

sequntial statement in python
Sequential Statement

2) Selection Statement: Some problem doesn’t solve by performing sequential statement, but they execute if a particular condition is true. There are three selection statements.

   i) if statement: if condition is true then it execute the statement. if condition is false, it doesn't execute any statement.

if condition in python
if condition
 
   ii) if-else statement:
if condition is true then it executes a statement and in case condition is false it executes other statement.

if else condition in python
if - else condition
  iii) if-elif-else statement: sometime we need to evaluate multiple statements to get a certain result. In such situation we use if-elif-else statement. It checks first if condition if it is true, it executes the statement. But if first condition is false, it goes to elif statement. Finally if none of condition is true, it execute else statement.
if elif else condition in python
if - elif else condition
3) Loop Statement: Loop statement is used to repeat a block of code based on a given condition. These statements are also called iterative statements. There are two types of loop statements
1) For loop: The for loop statements allow the user to repeat a set of statement multiple number of time. This statement is used when number of loops is known.

The syntax of for loop :
for x in range(start, stop, step):
Statement - 1

Program -1
Write a program to print ‘Hello Python five time.


for loop in python
For Loop in Python

Program -2
Write a program to print first five natural numbers.


for loop in python
For Loop in Python

Program - 3
Write a program to print even numbers between one to ten.

for loop in python
For Loop in Python


2) While loop: The while loop repeats a block of statements for a given number of times, until the given condition is false. In this loop first the condition is checked and if it is true, the block of statements runs until the condition becomes false.


Syntax of while loop :

while(condition):
Statement – 1


Program - 1
Write a program to add first five natural numbers.


while loop in python
While Loop in Python


No comments:

Post a Comment

Post Top Ad