Q1. What is the output of the following Python code?
x={1:"X",2:"Y",3:"Z"}
for i,j in x.items():
print(i,j,end=" ")
A. 1 X 2 Y 3 Z
B. 1 2 3
C. X Y Z
D. 1:”X” 2:”Y” 3:”Z”
Ans: A
Q2. What is output of the following Python code?
x = ['ab', 'cd']
for i in x:
i.upper()
print(x)
A. [‘ab’, ‘cd’]
B. [‘AB’, ‘CD’]
C. [None, None]
D. None of Above
Ans: A (list' object has no attribute 'upper')
Q3. What is the output of the following code?
y= ['ab', 'cd']
for i in y:
y.append(i.upper())
print(y)
A. [‘AB’, ‘CD’]
B. [‘ab’, ‘cd’, ‘AB’, ‘CD’]
C. [‘ab’, ‘cd’]
D. None of Above
Ans: D
Q4. What is the output of below Python code?
x = (j for j in range(3))
for j in x:
print(j)
for j in x:
print(j)
A. 0 1 2
B. error
C. 0 1 2 0 1 2
D. All of Above
Ans: A
Expl: We can loop over a generator object only once.
Q5. What is the output of the below Python code?
string = "This is Career Bodh Sansthan"
for i in string.split():
print (i, end=", ")
A. t, h, i, i,s, C,a, r, e,e,r,B,o,d,h,S,a,n,s,t,h,a,n
B. This, is, Career Bodh Sansthan,
C. This, is, Career, Bodh, Sansthan,
D. None of Above
Ans: C
Explanation: Variable i takes the value of one word at a time.
Q6. What is the output of Python program?
i = [0, 1, 2, 3]
for i[0] in i:
print(i[0])
A. 0 1 2 3
B. 0 1 2 2
C. 3 3 3 3
D. None of Above
Ans: A
Q7. What is the output of Python program?
print (0.1 + 0.2 == 0.3)
A. True
B. False
C. Error
D. None of Above
Ans: B
Q8. What is the output of Python program?
print (1 + 2 == 3)
A. True
B. False
C. Error
D. None of Above
Ans: A
Q9. What is the output of Python program?
print (01 + 02 == 03)
A. True
B. False
C. Error
D. Invalid
Ans: D
Q10. Which is the correct operator for power (xy)?
A. x^y
B. x**y
C. x^^y
D. None of Above
Ans: B
Q11. What is the output of the following Python program?
a = 123
for i in a:
print(i)
A. 1 2 3
B. 123
C. Error
D. None of Above
Ans: C (TypeError: 'int' object is not iterable)
.Q12. What is the output of following python program?
a = 1, 2, 3
for i in a:
print(i)
A. 1
2
3
B. 1,2,3
C. Error
D. None of Above
Ans: A
Q13. What is the output of Python code?
sum=0
x=[1,3,6,7]
for i in x:
sum=sum+i
print(sum)
A. 15
B. 17
C. 1367
D. None of Above
Ans: B
Q14. What is the output of following code?
for i in [0, 1, 2, 3]:
for j in [0, 1, 2, 3, 4]:
print('*')
A. 4 times *
B. 5 times *
C. 20 times *
D. 9 times *
Ans: C
Q15. Which statement is not printed when below python code is execute?
for i in 'Python':
if i == 'h':
continue
print('Current Letter : ' + i)
A. Current Letter : P
B. Current Letter : y
C. Current Letter : t
D. Current Letter : h
Ans: D
Q16. What is the purpose of a for loop in Python?
A. To call a function
B. To iterate over a sequence
C. To perform a logical operations
D. To perform arithmetic operations
Ans: B
For Loop MCQ Asked O Level Jan 2023 Exam NIELIT
Q17. What is the output of the following algorithm for a=5, b=8, c=6?
Step 1 : Start
Step 2 : Declare variables a, b and c.
Step 3 : Read variables a, b and c.
Step 4 : If a < b
If a < c
Display a is the smallest number.
Else
Display c is the smallest number.
Else
If b < c
Display b is the smallest number.
Else
Display c is the smallest number.
Step 5 : Stop
A. a is the smallest number
B. b is the smallest number
C. c is the smallest number
D. stop
Ans: A
Q18. What is the output of the following Python code?
print([i.lower() for i in “HELLO”])
(A) hello
(B) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
(C) hel
(D) HELLO
Ans: B
Q19. What is the output of the following python code?
d = {3, 4, 5}
for k in d:
print(k)
A. {3, 4, 5} {3, 4, 5} {3, 4, 5}
B. 3 4 5
C. Syntax Error
D. None of the above
Ans: B
Q20. The contents inside the “for loop” are separated by :
A. colon
B. comma
C. semicolon
D. hyphen
Ans: C
Q21. What is the output of the following python code ?
x=123
for i in x:
print(i)
A. 1 2 3
B. 123
C. Error
D. None of these
Ans: C
Q22. What is the output of the following python code?
numbers = (4, 7, 19, 2, 89, 45, 72, 22)
sorted_numbers = sorted(numbers)
odd_numbers = [x for x in sorted_numbers if x % 2 != 0]
print(odd_numbers)
(A) [7, 19, 45, 89]
(B) [2, 4, 22, 72]
(C) [4, 7, 19, 2, 89, 45, 72, 22]
(D) [2, 4, 7, 19, 22, 45, 72, 89]
Ans: A
Q23. What is the output of the following python code?
M=[‘b’ * x for x in range(4)]
print(M)
A. [‘’, ‘b’, ‘bb’, ‘bbb’]
B. [‘b’, ‘bb’, ‘bbb’, ‘bbbb’]
C. [ ‘b’, ‘bb’, ‘bbb’]
D. None of these
Ans: B
Q24. What is output of following python code?
x = 'abcd'
for i in x:
print(i.upper())
A. a B C D
B. a b c d
C. error
D. A B C D
Ans: D
Q25.What is the output of the following python code?
y = ‘klmn’
for i in range(len(y)):
print(y)
(A) klmn klmn klmn klmn
(B) k
(C) k k k
(D) None of the above
Ans: A
Q26. What is the output of the following Python code ?
def power(x, y=2):
r=1
for i in range(y):
r=r*x
return r
print (power(3))
print (power(3,3))
(A) 212
32
(B) 9
27
(C) 567
98
(D) None
Ans: B
Q27. What is output for the following python code ?
import numpy as np
a = np.array( [2, 3, 4, 5] )
print(a.dtype)
(A) int 64
(B) int
(C) float
(D) None
Ans: A
Kommentarer