0% found this document useful (0 votes)
24 views

Python ch-3 Questions Answers Full

The document discusses different types of control flow structures in Python including sequential, selection, and repetition structures. It provides examples of simple if, if-else, nested if, if-elif-else statements as well as for and while loops. It also explains break and continue statements giving examples of each.

Uploaded by

soulhazard8
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Python ch-3 Questions Answers Full

The document discusses different types of control flow structures in Python including sequential, selection, and repetition structures. It provides examples of simple if, if-else, nested if, if-elif-else statements as well as for and while loops. It also explains break and continue statements giving examples of each.

Uploaded by

soulhazard8
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Chapter – 3

Conditional and Looping Construct


(Questions and Answers)

Q.1 What do you mean by Control Flow in Python?

Ans. A program’s control flow is the order in which the program’s code executes.
The control flow of a Python program is regulated by conditional statements,
loops, and function calls.

Q.2 Write three types of control structures.


Ans. Python has three types of control structures:

❖ Sequential - default mode


❖ Selection - used for decisions and branching
❖ Repetition - used for looping, i.e., repeating a piece of code multiple
times.

Q.3 Explain Sequential control structure alongwith an example.


Ans. Sequential statements are a set of statements whose execution process happens in a
sequence. The problem with sequential statements is that if the logic has broken in
any one of the lines, then the complete source code execution will break.
Q.4 Define Selection/Decision-Control Statement with an example.

Ans. In Python, the selection statements are also known as Decision control
statements or branching statements.
The selection statement allows a program to test several conditions and execute
instructions based on which condition is true.
Some Decision Control Statements are:

❖ Simple if
❖ if-else
❖ nested if
❖ if-elif-else

Q.5 Explain the following terms with examples :-

(a) Simple if (b) if-else (c) nested if

(d) if – elif-else

Ans. (a) Simple if :

If statements are control flow statements that help us to run a particular


code, but only when a certain condition is met or satisfied. A simple if only
has one condition to check.

(b) if –else
The if-else statement evaluates the condition and will execute the body of if if
the test condition is True, but if the condition is False, then the body of else is
executed.
(c) nested – if

Nested if statements are an if statement inside another if statement exists.

(d) if – elif – else

The if-elif-else statement is used to conditionally execute a statement or a


block of statements.

Q.6 What do you mean by repetition statement in control flow structure? Write its
types.

Ans. A repetition statement is used to repeat a group(block) of programming


instructions.
In Python, we generally have two loops/repetitive statements:

❖ for loop
❖ while loop
Q.7 Explain for loop with an example.

Ans. for loop


A for loop is used to iterate over a sequence that is either a list, tuple, dictionary, or a
set.

Q.8 Explain while loop with an example.

Ans. In Python, while loops are used to execute a block of statements repeatedly until a
given condition is satisfied. Then, the expression is checked again and, if it is still
true, the body is executed again. This continues until the expression becomes false.
Q.9 What is a break statement? Write its example.

Ans. When a break statement is encountered inside a loop, the loop is immediately
terminated and the program control resumes at the next statement following the
loop.

Here, ‘Break’
statement will
stop printing
even numbers.

Q.10 What do you mean by continue statement? Explain it with an example.

Ans. The continue statement works somewhat like a break statement. Instead of forcing
termination, it forces the next iteration of the loop to take place, skipping any code
in between.

Here, ‘Continue’
statement will be
showing the
continued value but
will skip the
condition.

You might also like