EmSAT Achieve Exam  >  EmSAT Achieve Tests  >  Test: Loops - 2 - EmSAT Achieve MCQ Download as PDF

Test: Loops - 2 - EmSAT Achieve MCQ


Test Description

20 Questions MCQ Test - Test: Loops - 2

Test: Loops - 2 for EmSAT Achieve 2024 is part of EmSAT Achieve preparation. The Test: Loops - 2 questions and answers have been prepared according to the EmSAT Achieve exam syllabus.The Test: Loops - 2 MCQs are made for EmSAT Achieve 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Loops - 2 below.
Solutions of Test: Loops - 2 questions in English are available as part of our course for EmSAT Achieve & Test: Loops - 2 solutions in Hindi for EmSAT Achieve course. Download more important topics, notes, lectures and mock test series for EmSAT Achieve Exam by signing up for free. Attempt Test: Loops - 2 | 20 questions in 40 minutes | Mock test for EmSAT Achieve preparation | Free important questions MCQ to study for EmSAT Achieve Exam | Download free PDF with solutions
1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Loops - 2 - Question 1

Which statement is used to exit a loop prematurely in Python?

Detailed Solution for Test: Loops - 2 - Question 1

The break statement is used to exit a loop prematurely. When encountered, it terminates the loop and transfers control to the statement immediately following the loop.

Test: Loops - 2 - Question 2

What is the purpose of the range() function in a for loop?

Detailed Solution for Test: Loops - 2 - Question 2

The range() function is used in a for loop to generate a sequence of numbers to iterate over. It allows specifying the start, end, and step size of the sequence.

Test: Loops - 2 - Question 3

How many times will the following loop execute? for i in range(5):

Detailed Solution for Test: Loops - 2 - Question 3

The range(5) generates a sequence of numbers from 0 to 4 (5 numbers). The loop will execute five times, once for each number in the range.

Test: Loops - 2 - Question 4

What is the output of the following code?
for i in range(3):
    print(i)
else:
    print("Loop completed")

Detailed Solution for Test: Loops - 2 - Question 4

The loop iterates over the range range(3), which generates the numbers 0, 1, and 2. The else block is executed after the loop completes, printing "Loop completed."

Test: Loops - 2 - Question 5

Which loop is ideal to use when the number of iterations is unknown?

Detailed Solution for Test: Loops - 2 - Question 5

The while loop is ideal to use when the number of iterations is unknown because it repeatedly executes a block of code as long as a given condition is true.

Test: Loops - 2 - Question 6

What is the output of the following code?
num = 6
for i in range(2, num):
    if num % i == 0:
        print("Not a prime number")
        break
else:
    print("Prime number")

Detailed Solution for Test: Loops - 2 - Question 6

The loop checks if the given number num is divisible by any number from 2 to num-1. If it finds a factor, it prints "Not a prime number" and breaks out of the loop. Otherwise, it prints "Prime number."

Test: Loops - 2 - Question 7

Which loop construct allows the execution of a set of statements at least once, even if the loop condition is false?

Detailed Solution for Test: Loops - 2 - Question 7

In Python, there is no direct construct for a do-while loop. However, we can achieve the same behavior by using a while loop with an initial condition and then checking the loop condition.

Test: Loops - 2 - Question 8

How many times will the following loop execute? while True:

Detailed Solution for Test: Loops - 2 - Question 8

The condition True is always true, so the while loop will continue executing indefinitely unless there is a break statement or an external interrupt.

Test: Loops - 2 - Question 9

What is the output of the following code?
num = 10
if num % 2 == 0:
    print("Even")
else:
    print("Odd")

Detailed Solution for Test: Loops - 2 - Question 9

The code checks if the number num is divisible by 2 using the modulus operator (%). If the remainder is 0, it is an even number and "Even" is printed.

Test: Loops - 2 - Question 10

What is the output of the following code?
for i in range(5):
    if i == 3:
        break
    print(i)
else:
    print("Loop completed")

Detailed Solution for Test: Loops - 2 - Question 10

The loop iterates over the range range(5), which generates the numbers 0, 1, 2, 3, and 4. When i is equal to 3, the break statement is encountered, and the loop is terminated. The else block is not executed in this case.

Test: Loops - 2 - Question 11

What is the output of the following code?
for i in range(2, 10, 3): print(i, end=" ")

Detailed Solution for Test: Loops - 2 - Question 11

The range(2, 10, 3) generates a sequence of numbers starting from 2 and incrementing by 3 at each step until less than 10. The loop prints each number in the sequence.

Test: Loops - 2 - Question 12

What is the output of the following code?
num = 5
for i in range(num):
    if i == 3:
        continue
    print(i, end=" ")

Detailed Solution for Test: Loops - 2 - Question 12

The loop iterates over the range range(num), which generates the numbers 0, 1, 2, 3, and 4. When i is equal to 3, the continue statement is encountered, skipping the print statement for 3.

Test: Loops - 2 - Question 13

What is the output of the following code?
i = 1
while i < 5:
    print(i)
    if i == 3:
        break
    i += 1

Detailed Solution for Test: Loops - 2 - Question 13

The while loop executes until the condition i < 5 is false. Inside the loop, i is printed, and if it becomes equal to 3, the break statement is encountered, terminating the loop.

Test: Loops - 2 - Question 14

What is the output of the following code?
for i in range(5):
    if i == 2:
        continue
    print(i, end=" ")
else:
    print("Loop completed")

Detailed Solution for Test: Loops - 2 - Question 14

The loop iterates over the range range(5), which generates the numbers 0, 1, 2, 3, and 4. When i is equal to 2, the continue statement is encountered, skipping the print statement for 2. The else block is executed after the loop completes, printing "Loop completed."

Test: Loops - 2 - Question 15

What is the output of the following code?
num = 10
while num > 0:
    print(num, end=" ")
    num //= 2

Detailed Solution for Test: Loops - 2 - Question 15

The while loop repeatedly divides the number num by 2 and prints it. The //= operator performs integer division, discarding the remainder.

Test: Loops - 2 - Question 16

What is the output of the following code?
for i in range(2, 6):
    if i % 2 == 0:
        continue
    print(i, end=" ")

Detailed Solution for Test: Loops - 2 - Question 16

The loop iterates over the range range(2, 6), which generates the numbers 2, 3, 4, and 5. When i is divisible by 2, the continue statement is encountered, skipping the print statement for even numbers.

Test: Loops - 2 - Question 17

What is the output of the following code?
for i in range(3):
    for j in range(2):
        print(i + j, end=" ")

Detailed Solution for Test: Loops - 2 - Question 17

The nested loops iterate over the range range(3) and range(2). The print statement outputs the sum of i and j for each combination of i and j.

Test: Loops - 2 - Question 18

What is the output of the following code?
num = 5
for i in range(num):
    print(i, end=" ")
    if i == 2:
        break

Detailed Solution for Test: Loops - 2 - Question 18

The loop iterates over the range range(num), which generates the numbers 0, 1, 2, 3, and 4. When i is equal to 2, the break statement is encountered, terminating the loop.

Test: Loops - 2 - Question 19

What is the output of the following code?
num = 7
for i in range(2, num):
    if num % i == 0:
        print(i)
        break
else:
    print("Prime number")

Detailed Solution for Test: Loops - 2 - Question 19

The loop iterates over the range range(2, num), which generates the numbers from 2 to num-1. It checks if num is divisible by each number and prints the factors.

Test: Loops - 2 - Question 20

What is the output of the following code?
num = 10
for i in range(2, num):
    if num % i == 0:
        print("Not a prime number")
        break
else:
    print("Prime number")

Detailed Solution for Test: Loops - 2 - Question 20

The loop iterates over the range range(2, num), which generates the numbers from 2 to num-1. It checks if num is divisible by any number and prints "Not a prime number" if a factor is found. If the loop completes without finding any factors, it prints "Prime number."

Information about Test: Loops - 2 Page
In this test you can find the Exam questions for Test: Loops - 2 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Loops - 2, EduRev gives you an ample number of Online tests for practice
Download as PDF
Download the FREE EduRev App
Track your progress, build streaks, highlight & save important lessons and more!