MCQ Loop
MCQ Loop
8 Level:1
to Python"? B. 9
C. 10
count = 0 D. 11
while count < 10: E. 0
print("Welcome to Python")
count += 1 Answer:
C
Q2. What is the output of the following code? A. x is 0 Level:1
x=0 B. x is 1
while x < 4: C. x is 2
x=x+1 D. x is 3
E. x is 4
print("x is", x) Answer:
E
Q3. Analyze the following code. A. count < Level:2
100 is always
count = 0 True at Point
while count < 100: A
# Point A B. count <
print("Welcome to Python!") 100 is always
count += 1 True at Point
# Point B B
C. count <
# Point C 100 is always
False at Point
B
D. count <
100 is always
True at Point
C
E. count <
100 is always
False at Point
C
Answer;
A,E
Q4. How many times will the following code print "Welcome A. 8 Level:1
to Python"? B. 9
count = 0 C. 10
while count < 10: D. 11
print("Welcome to Python") E. infinite
number of
times
Answer E
Q5. What will be displayed when the following code is A. 6 3 0 Level:2
executed? B. 6 3
C. 3 0
number = 6 D. 3 0 -3
while number > 0: E. 0 -3
number -= 3
print(number, end = ' ') Answer
C
Q6. Analyze the following statement: A. The Level:2
program has
sum = 0 a syntax
for d in range(0, 10, 0.1): error
sum += sum + d because the
range
function
cannot have
three
arguments.
B. The
program has
a syntax
error
because the
arguments in
the range
must be
integers.
C. The
program
runs in an
infinite loop.
D. The
program
runs fine.
Answer:
B
Q7. Which of the following loops correctly computes 1/2 + A. BCD Level:3
2/3 + 3/4 + ... + 99/100? B. ABCD
C. B
A: D. CDE
sum = 0 E. CD
for i in range(1, 99):
sum += i / (i + 1) Answer:
C:
sum = 0
for i in range(1.0, 99.0):
sum += i / (i + 1)
D:
sum = 0
for i in range(1.0, 100.0):
sum += i / (i + 1)
Q11 To add 0.01 + 0.02 + ... + 1.00, what order should you A. add 0.01, Level:2
use to add the numbers to get better accuracy? 0.02, ..., 1.00
in this order
to a sum
variable
whose initial
value is 0.
B. add 1.00,
0.99, 0.98,
..., 0.02, 0.01
in this order
to a sum
variable
whose initial
value is 0
Answer:
A
Q12 How many times is the print statement executed? A. 100 Level:2
for i in range(10): B. 20
for j in range(10): C. 10
print(i * j) D. 45
Answer:100
Q13 Will the following program terminate? A. Yes Level:2
B. No
balance = 10
Answer:
while True: A
if balance < 9: break
balance = balance - 9
Q14. What is sum after the following loop terminates? A. 15 Level:3
B. 16
sum = 0 C. 17
item = 0 D. 18
while item < 5:
item += 1 Answer;
sum += item A
if sum >= 4: continue
print(sum)
Q15. What will be displayed by after the following loop A. i is 5 Level:3
terminates? isPrime is
True
number = 25 B. i is 5
isPrime = True isPrime is
for i in range(2, number): False
if number % i == 0: C. i is 6
isPrime = False isPrime is
break True
D. i is 6
print("i is", i, "isPrime is", isPrime) isPrime is
False
Answer: B
Q16. Suppose the input for number is 9. What will be A. i is 3 Level:3
displayed by the following program? followed by
9 is prime
number = eval(input("Enter an integer: ")) B. i is 3
followed by
isPrime = True 9 is not
for i in range(2, number): prime
if number % i == 0: C. i is 2
isPrime = False followed by
9 is prime
print("i is", i) D. i is 2
followed by
if isPrime: 9 is not
print(number, "is prime") prime
break Answer; C
else:
print(number, "is not prime")