Chapter 8
More about Python
A. Fill in the blanks.
1. The continue statement skips the rest of the loop statements and
causes the next iteration of the loop to take place.
2. The break statement enables a program to skip over a part of the code.
3. The else part of the while loop is executed only when the while loop
completes all its iterations.
4. Condition is checked for True or False, and the statements are executed
only if the condition is true.
5. The while loop is helpful when the number of iterations are not known
prior to the execution of the loop.
B. Give the output for the following codes.
1. Num=0
while (Num<10):
Num+=1
if Num==5
Break
print(Num,end=”,”)
Output: 1,2,3,4
2. for val in “string”:
if val==”l”
break
print(val)
print(“over”)
OUTPUT: s
t
r
i
n
g
Over
C. Answer the following questions.
1. What is the significance of using iterations in Python?
Ans: By using iteration, we can easily repeat a task a certain
number of times or for each item in a sequence.
2. Explain the range () function with the help of an example.
Ans: The range() function is used to create a list containing a
sequence of numbers starting from start and ending with one
less than the stop.
3. Explain the difference between FOR and WHILE loops.
Ans: The FOR..structure is used to repeat a loop a specific
number of times. A WHILE loop executes a block of code
repeatedly as long as the condition of the loop is true.
4. What are jump statements?
Ans: The statements which are used within loops to quit out
of loop iterations are called jump statements.
Eg: break statement, jump statement