NEW
Font size
WorksheetsDay - 5 - Loops Wipro TN
Total questions: 21
Worksheet time: 32mins
In programming, what is iteration/looping?
The repetition of steps within a program
The order in which instructions are carried out
A decision point in a program
print(str(i) * 5)
print("i" * i)
print("i" * i)
print(str(i) * i)
What is the value of num when this loop completes?
num = 0
for i in range(2, 8, 2):
num += i
2
8
12
20
What is the value of num when this loop completes?
num = 0
for i in range(2, 8, 2):
num += i
2
8
12
20
Three of the for loops below will provide identical values for i. Which for loop will provide values that do not match the others?
for i in range(0, 5):
for i in range(5):
for i in range(0, 5, 1):
for i in range(5, 0, 1):
What is the value of the variable sum after the code above executes
54
44
64
34
74
output of the following code is -
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
Hello world!
Hello world!
break
Error
What is the difference between break and continue statements?
The 'break' statement skips to the next iteration, while 'continue' exits the loop.
The 'break' statement is used only in switch cases, while 'continue' is for loops.
Both 'break' and 'continue' exit the loop but have different conditions.
The 'break' statement exits a loop, while the 'continue' statement skips to the next iteration of the loop.
What is the purpose of the range() function in Python?
To create a random number generator.
To convert a string to an integer.
To sort a list of numbers.
To generate a sequence of numbers.
How do you ensure a while loop eventually stops executing?
Modify the loop condition or a variable within the loop to ensure it will eventually evaluate to false.
Remove the loop condition entirely.
Use a break statement without a condition.
Increase the loop counter indefinitely.
Given the nested if-else below, what will be the value x when the code is executed successfully.
0
4
2
3
Given the nested if-else structure below, what will be the value of x after code execution completes.
2
0
3
4
What is the output of the following nested loop?
10 Chair
10 Table
20 Chair
20 Table
10 Chair
10 Table
What is the output of the following if statement?
False
True
What is the value of the var after the for loop completes its execution?
20
21
10
30
What is the value of x after the following nested for loop completes its execution?
99
90
100
0
Select which is true for: (for loop).
Hint: (We use while loop when we want to perform a task indefinitely until a particular condition is met.)
Python’s for loop used to iterates over the items of list, tuple, dictionary, set, or string.
We use for loop when we want to perform a task indefinitely until a particular condition is met
else clause of for loop is executed when the loop terminates abruptly
else clause of for loop is executed when the loop terminates naturally
Whats the output?
1
2
3
5
A
B
C
D
A
B
C
D
