iNeuron Day 10 python interview questions
iNeuron Day 10 python interview questions
A. for loop
B. while loop
C. do-while loop
D. None of the above
Ans: C
ExplanaDon: do-while loop is not used as loop in Python.
Ans: B
ExplanaDon: While loop is used when mulDple statements are to
executed repeatedly unDl the given condiDon becomes False
statement is False regarding loops in Python.
n=7
c=0
while(n):
Page 2 of 11
iNeuron Intelligence Pvt Ltd
if(n>5):
c=c+n-1
n=n-1
else:
break
print(n)
print(c)
A. 5 11
B. 5 9
C. 7 11
D. 5 2
Ans: A
ExplanaDon: 5 11 will be the output of the given code
for i in range(0,2,-1):
print("Hello")
A. Hello
B. Hello Hello
Page 3 of 11
iNeuron Intelligence Pvt Ltd
C. No Output
D. Error
View Answer
Ans: C
ExplanaDon: There will be no output of the following python code.
A. else if
B. elseif
C. elif
D. None of the above
View Answer
Ans : C
ExplanaDon: elif is used to add an alternaDve condiDon to an if
statement. So, opDon C is correct.
A. Yes
B. No
C. if/else not used in python
D. None of the above
View Answer
Ans : A
Page 4 of 11
iNeuron Intelligence Pvt Ltd
Ans: A
Explanation: If condition is true so pq will be the output. So, option A
is correct.
A. if a = b:
B. if a == b:
C. if a === c:
D. if a == b
View Answer
Ans: B
Explanation: if a == b: statement will check if a is equal to b. So,
option B is correct.
A. indefinite
B. discriminant
Page 5 of 11
iNeuron Intelligence Pvt Ltd
C. definite
D. indeterminate
Ans: A
ExplanaDon: A while loop implements indefinite iteraDon, where the
number of Dmes the loop will be executed is not specified explicitly
in advance. So, opDon A is correct.
10. When does the else statement wri`en aaer loop executes?
Ans: B
ExplanaDon: Else statement aaer loop will be executed only when
the loop condiDon becomes false. So, opDon B is correct.
A. TRUE
B. FALSE
C. Null
D. Both A and C
Page 6 of 11
iNeuron Intelligence Pvt Ltd
View Answer
Ans: B
12. If the else statement is used with a while loop, the else statement
is executed when the condition becomes _______.
A. TRUE
B. FALSE
C. Infinite
D. Null
Ans: B
Explanation: If the else statement is used with a while loop, the else
statement is executed when the condition becomes false.
Page 7 of 11
iNeuron Intelligence Pvt Ltd
A. break
B. exit
C. return
D. pass
Ans: D
Explanation: The pass statement is a null operation; nothing happens
when it executes.
A. while loop
B. for loop
C. do-while
D. Both A and B
Ans: D
Explanation: The continue statement can be used in both while and
for loops.
Ans: B
Page 8 of 11
iNeuron Intelligence Pvt Ltd
ExplanaDon: For statement always ended with colon (:). So, opDon B
is correct.
Ans: C
ExplanaDon: The iniDal value is 5 which is decreased by 2 Dll 0 so we
get 5, then 2 is decreased so we get 3 then the same thing repeated
we get 1 and now when 2 is decreased we get -1 which is less than 0
so we stop and hence we get 5 3 1. So, opDon C is correct.
17. When does the else statement wri`en aaer loop executes?
Ans: B
Page 9 of 11
iNeuron Intelligence Pvt Ltd
A. break
B. exit
C. return
D. pass
View Answer
Ans: D
ExplanaDon: The pass statement is a null operaDon; nothing happens
when it executes.
A. while loop
B. for loop
C. do-while
D. Both A and B
View Answer
Ans: D
ExplanaDon: The conDnue statement can be used in both while and
for loops
list1 = [3 , 2 , 5 , 6 , 0 , 7, 9]
sum = 0
Page 10 of 11
iNeuron Intelligence Pvt Ltd
sum1 = 0
if (elem % 2 == 0):
conDnue
if (elem % 3 == 0):
print(sum1)
A. 8 9
B. 8 3
C. 2 3
D. 8 12
View Answer
Ans- D
ExplanaDon: The output of the following python code is 8 12.
Page 11 of 11