Python Q & A Chapter 2
A. Tick the correct option –
1. (c) Boolean
2. (d) Level
3. (a) Built-in
4. (c) both (a) and (b)
5. (b) control
B. Very Short Answer Type Questions –
1. What is control variable?
The variable which controls the flow of execution of the
program is called control variable. These control variables are used in
Decision Making statements or Looping statements.
2. What do you mean by Flow of Control?
A computer always executes a program sequentially. It starts
execution from the first statement and ends at the last statement. This order
of execution of statements is called Flow of Control.
3. How many types of loops are there in Python?
There are two types of loops in python, For loop and While
loop.
4. In how many ways you can call range() in Python?
The range() function can be called by three ways. The
range() function can be used with three arguments depending on the need of the
programmer.
5. Write the syntax of For loop.
for <variable> in range(start, stop, step):
[statement in body of
loop]
C. Short answer type questions –
1. Describe the ways in which range() function is called.
The range is built in function in Python that allows you to
generate a series of numbers within a given range. There are three ways you can
call range():
- Range(stop)
- Range(start, stop)
- Range(start, stop, step)
(a) range(n) – It takes one argument and generates a set of
whole numbers starting from 0 to (n – 1). E.g. range(8) is equivalent to
[0,1,2,3,4,5,6,7]
(b) range(start, stop) – It takes two arguments, and
generates a set of whole numbers starting from start to stop. E.g. range(3,9)
is equivalent to [3,4,5,6,7,8]
(c) range(start, stop, step) – It takes three arguments and
generates a set of whole numbers starting from start to stop having the
difference of step. E.g. range(1,10,2) is equivalent to [1,3,5,7,9]
2. What is the significance of indentation in python program?
In python program indentation has a special role. It is used
to define compound statements or blocks. In a python program, contiguous
statements that are indented to the same level are considered part of the same
block.
3. What is looping statement?
The looping or iterative statements are used for repeating a
set of statements multiple items in a row. In python there are two types of
loops while and for loops.
4. Differentiate between
(a) for loop and while loop
For loops are used when you have a block of code which you
want to repeat a fixed number of times. The for loop in python is used to print
a sequence like list, tuple or dictionary.
The while loop in python is also known as pre tested loop.
It allows the block of code to be executed till the condition is true.
(b) If statement and If else statement
The if statement only execute one type of statement which can be either true or false. But in if else statement is able to execute both type of statements which can be either true or false.
Comments
Post a Comment
Students you can ask your doubts in comment section