wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

LOOPS

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which is the correct output for :

for i in range(1,10):

print(i)

a)

1,2,3,4,5,6,7,8,9

b)

1,2,3,4,5,6,7,8,9,10

c)

0,1,2,3,4,5,6,7,8,9,10

d)

1,2,3,4,5,6,7,8

2.

What is a loop?

a)

A loop without conditions

b)

A loop with an if statement

c)

In computer programming, a loop is an order of instructions that repeats for many times

3.

Which is not a valid Python loop?

a)

for loop

b)

while loop

c)

iter loop

4.

for num in [11, 9, 88, 10, 90, 3, 19]:

print(num)

if(num==88):

print("The number 88 is found")

print("Terminating the loop")

break


Output?

a)

11

9

88

The number 88 is found

Terminating the loop

b)

11

88

9

The number 88 is found

Terminating the loop

c)

9

88

10

The number 88 is found

Terminating the loop

d)

88

10

90

The number 88 is found

Terminating the loop

5.

Each repetition is called ... of loop

a)

counter

b)

iteration

c)

number of loops

d)

starting value

6.

What Is Range() Function?

a)

The first is the iterable object such as a list, tuple or a string.

b)

The “iter” represents the iterating variable.

c)

The “sequence” may refer to any of the following Python objects such as a list, a tuple or a string.

d)

The range() function can produce an integer sequence at runtime.

7.

What Is A Python For Loop?

a)

The range() function can produce an integer sequence at runtime.

b)

The “sequence” may refer to any of the following Python objects such as a list, a tuple or a string.

c)

A for loop in Python requires at least two variables to work.

8.

for a in range(4):

print(a)


OUTPUT?

a)

0

1

2

3

b)

1

2

3

c)

0

2

4

d)

0

1

2

3

4

9.

numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9) # Declaring the tuple

count_odd = 0

count_even = 0

for x in numbers:

if x % 2:

count_odd+=1

else:

count_even+=1

print("Number of even numbers :",count_even)

print("Number of odd numbers :",count_odd)

a)

Number of even numbers:5

Number of odd numbers: 4

b)

Number of even numbers:4

Number of odd numbers: 5

c)

Number of even numbers:3

Number of odd numbers: 4

d)

Number of even numbers:5

Number of odd numbers: 3

10.

for i in range(1,100):

if i%2!=0:

print(i)

Output?

a)

prints all even numbers

b)

prints all odd numbers

c)

prints all even,odd numbers