wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Day - 5 - Loops Wipro TN

Total questions: 21

Worksheet time: 32mins

Name
Class
Date
1.

In programming, what is iteration/looping?

a)

The repetition of steps within a program

b)

The order in which instructions are carried out

c)

A decision point in a program

2.
Why is iteration important?
a)
It determines the order in which instructions are carried out
b)
It allows code to be simplified by removing duplicated steps
c)
It allows multiple paths through a program
3.
Which of the following will print:
a)
for i in range(1, 5):   
print(str(i) * 5)
b)
for i in range(1, 5):   
print("i" * i)
c)
for i in range(1, 6):   
print("i" * i)
d)
for i in range(1, 6):   
print(str(i) * i)
4.

What is the value of num when this loop completes?


num = 0

for i in range(2, 8, 2):

num += i

a)

2

b)

8

c)

12

d)

20

5.

What is the value of num when this loop completes?


num = 0

for i in range(2, 8, 2):

num += i

a)

2

b)

8

c)

12

d)

20

6.

Three of the for loops below will provide identical values for i. Which for loop will provide values that do not match the others?

a)

for i in range(0, 5):

b)

for i in range(5):

c)

for i in range(0, 5, 1):

d)

for i in range(5, 0, 1):

7.

What is the value of the variable sum after the code above executes

a)

54

b)

44

c)

64

d)

34

e)

74

8.

output of the following code is -

a)

Hello world!

Hello world!

Hello world!

Hello world!

Hello world!

Hello world!

(repeated continuously)

b)

Hello world!

c)

Hello world!

break

d)

Error

9.

What is the difference between break and continue statements?

a)

The 'break' statement skips to the next iteration, while 'continue' exits the loop.

b)

The 'break' statement is used only in switch cases, while 'continue' is for loops.

c)

Both 'break' and 'continue' exit the loop but have different conditions.

d)

The 'break' statement exits a loop, while the 'continue' statement skips to the next iteration of the loop.

10.

What is the purpose of the range() function in Python?

a)

To create a random number generator.

b)

To convert a string to an integer.

c)

To sort a list of numbers.

d)

To generate a sequence of numbers.

11.

How do you ensure a while loop eventually stops executing?

a)

Modify the loop condition or a variable within the loop to ensure it will eventually evaluate to false.

b)

Remove the loop condition entirely.

c)

Use a break statement without a condition.

d)

Increase the loop counter indefinitely.

12.

Given the nested if-else below, what will be the value x when the code is executed successfully.

a)

0

b)

4

c)

2

d)

3

13.

Given the nested if-else structure below, what will be the value of x after code execution completes.

a)

2

b)

0

c)

3

d)

4

14.

What is the output of the following nested loop?

a)

10 Chair

10 Table

20 Chair

20 Table

b)

10 Chair

10 Table

15.

What is the output of the following if statement?

a)

False

b)

True

16.

What is the value of the var after the for loop completes its execution?

a)

20

b)

21

c)

10

d)

30

17.

What is the value of x after the following nested for loop completes its execution?

a)

99

b)

90

c)

100

d)

0

18.

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.)

a)

Python’s for loop used to iterates over the items of list, tuple, dictionary, set, or string.

b)

We use for loop when we want to perform a task indefinitely until a particular condition is met

c)

else clause of for loop is executed when the loop terminates abruptly

d)

else clause of for loop is executed when the loop terminates naturally

19.

Whats the output?

a)

1

b)

2

c)

3

d)

5

20.
a)

A

b)

B

c)

C

d)

D

21.
a)

A

b)

B

c)

C

d)

D