MCQ on for loop in Python class 11

MCQ on for loop in Python class 11

Iterative (loop) Statements




Q.1 The for loop in Python is an _____________

a) Entry Controlled Loop

b) Exit Controlled Loop

c) Both of the above

d) None of the above

 

Q.2 break in Python is used ______________

a) To restart a loop

b) Terminate a loop

c) To jump in between the loop

d) None of the above

 

Q.3 A loop block in python starts with a –

a) ; (semicolon)

b) , (comma)

c) : (colon)

d) # (hash)

 




Q.4 Which of the following loop is not supported by the python programming language?

a) for loop

b) while loop

c) do…while loop

d) None of the above

 

Q.5 Which of the following is not a valid keyword of Python associated with loops?

a) continue

b) check

c) range

d) break

 

Q.6 Select which is true for, for loop

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

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

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

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

 

Q.7 Which of the following is False regarding loops in Python?

a)Loops are used to perform certain tasks repeatedly.

b) while loop is used when multiple statements are to executed repeatedly until the given condition becomes true.

c) while loop is used when multiple statements are to executed repeatedly until the given condition becomes false.

d) for loop can be used to iterate through the elements of lists.

 

Q.8 Which of the following is True regarding loops in Python?

a) Loops should be ended with keyword “end”.

b) No loop can be used to iterate through the elements of strings.

c) continue is used to continue with the remaining statements inside the loop.

d) break can be used to bring control out of the current loop.

 

Q.9 When does the else statement written after loop executes?

a) When loop condition becomes false

b) When break statement is executed in the loop

c) else statement is always executed

d) None of the above

 

Q.10 ________ in Python is a counter-controlled loop.

a) for

b) while

c) Both (a) and (b)

d) None of the above

 

Q.11 A count controlled loop will :

a) Repeat code until a condition is met

b) Repeat code a specific amount of times

c) Repeat code a random amount of times

d) None of the above

 

Q.12 I wants to continuously check for a correct answer each time user enters a value, what loop would I use?

a) for loop

b) while loop

 

Q.13 What is another word for ‘iteration’ ?

a) Selection

b) Assignment

c) Sequencing

d) Repetition

 

Q.14 X wants to allow the program to repeatedly ask the user to enter their Choice if it does not equal the Answer. Which loop option should X use?

a) while Choice == Answer:

Choice = input()

b) while Choice != Answer:

Choice = input()

c) while Answer != Choice:

Choice = input()

d) while Answer =! Choice:

Choice = input()

 

Q.15 Code repeated / looped until a condition has been met or a set number of times.

a) Sequence

b) Iteration

c) Selection

d) Variable

 

Q.16 Why is iteration important?

a) It determines the order in which instructions are carried out

b) It allows multiple paths through a program

c) It allows code to be simplified by removing repeated steps

d) It ensures the code works correctly

 

Q.17 Which term describes a loop that continues repeating without a terminating (ending) condition?

a) Infinite Loop

b) Conditional Loop

c) Unlimited Loop

d) Sequence Loop

 

Q.18 To access a list which contains ten elements, which of the following uses of range() would produce a list of the desired indexes?

a) range(1,10)

b) range(0,9)

c) range(10)

d) range(1,11)

 

Q.19 How would you create a loop to iterate over the contents of the list given as?

monthDays = [31,28,31,30,31,30,31,31,30,31,30,31]

and print out each element?

a) for days in range(monthDays):

print(days)

b) for days in monthDays:

print(days)

c) for days in range(len(monthDays)):

print(days)

d) for days in monthDays[0]:

print(days)

 

Q.20 Write the output of the following Python code:

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

print(i * ‘$’)

a) 2$

4$

6$

b) $$

$$$$

$$$$$$

c) 2$4$6$

d) None of the above

 

Q.21 Find and write the output of the following python code:

x = “abcdef”

i = “a”

while i in x:

print(i, end = ” “)

a) a

b) a a a a a a

c) a a a a a a … infinite times

d) Code will generate error

 

Q.22 Find the output of the following program segments:

a = 110

while a > 100:

print(a, end=’#’)

a –= 2

a) 110#108#106#104#102#100#

b) 110#108#106#104#102#

c) 110#108#106#104#102#

d) None of the above

 

Q.23 Find the output of the following program segments:

for i in range(20,30,2):

print(i)

a) 20 22 24 26 28

b) 20

22

24

26

28

c) 20 22 24 26 28 30

d) 20

22

24

26

28

30

 

Q.24 Find the output of the following program segments:

country = ‘INDIA’

for i in country:

print (i, end=”)

a) INDIA

b) I N D I A

c) I

N

D

I

A

d) INDI

 

Q.25 Find the output of the following program segments:

i = 0

sum = 0

while i < 9:

if i % 4 == 0:

sum = sum + i

i = i + 2

print (sum)

a) Infinite Loop

b) 12

c) 14

d) 10

 

Q.26 Find the output of the following program segments:

for x in range(1,4):

for y in range(2,5):

if x * y > 6:

break

print (x * y)

 

Q.27 Iteration stands for ___________

a) The order in which instructions are carried out

b) A decision point in a program

c) The repetition of steps within a program 

d) Testing a program to make sure it works

 

Q.28 Which of the following is consider as an infinite loop?

a) while(infinte):

b) while(1):

c) while(not 1):

d) while(!1)

 

Q.29 How many times the message Hello will appear when this loop runs?

while(0):

print(‘Hello’)

a) Not at all

b) Only once

c) Two times

d) Infinite times

 

Q.30 How many times will this loop run?

while(1):

print(2)

a) 1 time

b) 2 times

c) 3 times

d) None of the above

 

Q.31 How many times will this loop run?

while(1==2):

pass

a) 0

b) 1 

c) 3

d) Infinite

 

Q.32 Does Python support Exit – Controlled Loop?

a) Yes

b) No

 

Q.33 Which of the following is not true for the for statement in Python?

a) The statements within the body of for loop are executed till the range of values is exhausted

b) for loop iterates over the range or sequence.

c) for loop cannot be nested.

d) break statement is used to terminate a for loop without completing its iteration.

 

Q.34 Which of the following call to range() in Python will not yield anything?

a) range(-5, -1)

b) range(-1, -5, -1)

c) range(-5)

d) All of the above

 

Q.35 What will be the final value of I after execution of the loop:

for I in range(10):

print(I)

a) 10

b) 9

c) None

d) Error 

 

Q.36 range(3) in Python is equivalent to:

a) range(0,3,1)

b) range(1,4,1)

c) range(1,3)

d) range(1,3,0)

 

Q.37 What will be the output of the given program segment?

for I in range(10, 1, 1):

print(I)

print(I)

a) 10

b) 9

c) Error

d) None of the above

 

Q.38 Which is not correct for the repetition constructs in Python?

a) For a for loop, an equivalent while loop can always be written.

b) For a while loop, an equivalent for loop can be written.

c) continue cannot be used with for loops.

d) else can be used with for and while both.

 

Q.39 Which of the following is not a valid jump statement in Python?

a) break

b) goto

c) call

d) continue

 

Q.40 What is the result of executing the following code?

count = 10

while count <= 10:

if count < 10:

count = count + 1

print(count)

a) The program will loop indefinitely

b) The value of number will be printed exactly 1 time

c) The while loop will never get executed

d) The value of number will be printed exactly 5 times

Leave a Reply

Your email address will not be published. Required fields are marked *