0% found this document useful (0 votes)
7 views

iNeuron Day 10 python interview questions

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

iNeuron Day 10 python interview questions

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

iNeuron Intelligence Pvt Ltd

1. Which of the following is not used as loop in Python?

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.

2. 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 mulDple statements are to executed
repeatedly unDl the given condiDon becomes False
C. While loop is used when mulDple statements are to executed
repeatedly unDl the given condiDon becomes True.
D. for loop can be used to iterate through the elements of lists.

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.

3. What will be the output of given Python code?

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

4. What will be the output of the following Python 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.

5. What keyword would you use to add an alternaDve condiDon to an


if statement?

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.

6. Can we write if/else into one line in python?

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

ExplanaDon: Yes, we can write if/else in one line. For eg i = 5 if a > 7


else 0. So, opDon A is correct.

7. What will be output of this expression:

'p' + 'q' if '12'.isdigit() else 'r' + 's'


A. pq
B. rs
C. pqrs
D. pq12
View Answer

Ans: A
Explanation: If condition is true so pq will be the output. So, option A
is correct.

8. Which statement will check if a is equal to b?

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.

9. A while loop in Python is used for what type of iteraDon?

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?

A. When break statement is executed in the loop


B. When loop condiDon becomes false
C. Else statement is always executed
D. None of the above

Ans: B
ExplanaDon: Else statement aaer loop will be executed only when
the loop condiDon becomes false. So, opDon B is correct.

11. A loop becomes infinite loop if a condition never becomes


________.

A. TRUE

B. FALSE

C. Null

D. Both A and C

Page 6 of 11
iNeuron Intelligence Pvt Ltd

View Answer

Ans: B

Explanation: A loop becomes infinite loop if a condition never


becomes FALSE. You must use caution when using while loops
because of the possibility that this condition never resolves to a
FALSE value. This results in a loop that never ends. Such a loop is
called an infinite loop.

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.

13. The ________ statement is a null operation.

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.

14. The continue statement can be used in?

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.

15. Which of the following is a valid for loop in Python?

A. for(i=0; i < n; i++)


B. for i in range(0,5):
C. for i in range(0,5)
D. for i in range(5)
View Answer

Ans: B

Page 8 of 11
iNeuron Intelligence Pvt Ltd

ExplanaDon: For statement always ended with colon (:). So, opDon B
is correct.

16. Which of the following sequences would be generated bt the


given line of code?

range (5, 0, -2)


A. 5 4 3 2 1 0 -1
B. 5 4 3 2 1 0
C. 5 3 1
D. None of the above
View Answer

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?

A. When break statement is executed in the loop


B. When loop condiDon becomes false
C. Else statement is always executed
D. None of the above

Ans: B

ExplanaDon: Else statement aaer loop will be executed only when


the loop condiDon becomes false. So, opDon B is correct.

Page 9 of 11
iNeuron Intelligence Pvt Ltd

18. The ________ statement is a null operaDon.

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.

19. The conDnue statement can be used in?

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

20. What will be the output of the following Python code?

list1 = [3 , 2 , 5 , 6 , 0 , 7, 9]

sum = 0

Page 10 of 11
iNeuron Intelligence Pvt Ltd

sum1 = 0

for elem in list1:

if (elem % 2 == 0):

sum = sum + elem

conDnue

if (elem % 3 == 0):

sum1 = sum1 + elem

print(sum , end=" ")

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

You might also like