Answer of Loop Chapter
A. 1. The else block makes sure that the loop is terminated normally.
2. The in operator checks whether a given value lies within a given set of values.
3. The for loop is used when you are sure about how many times a loop body will be executed.
4. The range( ) function produces a list (or sequence) starting with an initial value up to a final
value.
5. An iterative statement is also known as a looping statement.
B. 1. Loops are also known as iterative statements.
2. The in operator checks whether a given value is a part of the specified sequence.
3. The while loop can be applied to a program where the number of iterations is not known
beforehand.
4. A for or while loop can have an optional else block as well.
5. The range() function produces a list of a sequence .
C. Write True or False
1. An iterative statement is based on three values. → F
2. The range() function, by default, the value is incremented by 1. → T
3. There are two types of iterative statements: if and else. → F
4. The iterative statements keep on repeating a set of statements as long as the given condition
is false. → F
5. The loop.... else statement is optional to be used in a program. → T
D. Answer the following
1. What do you mean by iterative statements? Give an example from your real life.
Iterative statements are statements that allow a set of instructions to be executed repeatedly
as long as a certain condition is true. They are also called loops.
Real-life example: Brushing teeth involves repeating steps (apply paste, brush left, brush right,
rinse) until the teeth are clean. Similarly, a computer repeats instructions in a loop until the
condition is satisfied.
2. What are the membership operators in Python? Briefly explain their uses.
Python has two membership operators:
There are two types of membership operator in Python
a) in → Returns True if a value exists in a sequence (like list, tuple, string, set, or dictionary).
b) not in → Returns True if a value does not exist in a sequence.
3. Explain the use of range() function.
The `range()` function generates a sequence of numbers. It is commonly used in for loops to
repeat a block of code a specific number of times.
Syntax: range(start, stop)
range(start, stop, step)
4. Differentiate between for and while loop.
for Loop : Used when the number of iterations is known in advance and ends automatically
after the sequence is exhausted.
while loop : Used when the number of iterations is not known in advance and ends only when
the condition becomes false.
5. Is it possible to create an infinite loop? If yes, write a code to show infinite loop?
Yes, it is possible to create an infinite loop when the loop condition never becomes false.
Ex: s=0
while s>=1:
print(s)
s=s+1
E. Application based questions.
1. Prateek was writing a program to check whether a given number is divisible by 7 or not.
Which conditional statement should he use to achieve the desired result?
He should use the if…else` conditional statement with the modulus (%) operator.
num = int(input("Enter a number: "))
if num % 7 == 0:
print("The number is divisible by 7")
else:
print("The number is not divisible by 7")
2. Kirti wants to display all the numbers from 1 to 100. How will she do it?
She can use a for loop with the range() function.
EX : for i in range(1, 101):
print(i)