Anjeev Singh Academy

50+ Find the output of Python Code important questions

Find the output of the given Python Code
Important Interview Questions (Set-2)


Que 16. Identify the output of the following Python statement :

x = 2
while x < 9:
       print(x, end='')
       x = x + 1

a. 12345678
b. 123456789
c. 2345678
d. 23456789

ANSWER:

c. 2345678


Que 17. Identify the output of the following Python statement :

b = 1
for a in range(1, 10, 2):
       b += a + 2
print(b)

a. 31
b. 33
c. 36
d. 39

ANSWER:

c. 36


Que 18. Identify the output of the following Python statement :

lst1 = [10, 15, 20, 25, 30]
lst1.insert( 3, 4)
lst1.insert( 2, 3)
print (lst1[-5])

a. 2
b. 3
c. 4
d. 20

ANSWER:

b. 3


Que 19. What will be the output of the following Python code?

def add (num1, num2):
        sum = num1 + num2

sum = add(20,30)
print(sum)

a. 50
b. 0
c. Null
d. None

ANSWER:

d. None

By default, the function returns a None value in Python.


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

def my_func(var1=100, var2=200):
       var1 += 10
       var2 = var2 - 10
       return var1+var2

print(my_func(50),my_func())

a. 100 200
b. 150 300
c. 250 75
d. 250 300

ANSWER:

d. 250 300


Que 21. What will be the output of the following Python code?

value = 50
def display(N):
       global value
       value = 25
       if N%7 == 0:
               value = value + N
      else:
               value = value - N

print(value, end="#")

display(20)

print(value)

a. 50#50
b. 50#5
c. 50#30
d. 5#50#

ANSWER:

b. 50#5


Que 22. What will be the output of the following Python code?

import random

List=["Delhi","Mumbai","Chennai","Kolkata"]

for y in range(4):
      x = random.randint(1,3)
      print(List[x],end="#")

a. Delhi#Mumbai#Chennai#Kolkata#
b. Mumbai#Chennai#Kolkata#Mumbai#
c. Mumbai# Mumbai #Mumbai # Delhi#
d. Mumbai# Mumbai #Chennai # Mumbai

ANSWER:

b. Mumbai#Chennai#Kolkata#Mumbai#


Que 23. What will be the output of the following Python code? [CBSE 2020]

def ChangeVal(M,N):
        for i in range(N):
               if M[i] % 5 == 0:
                        M[i] //= 5
               if M[i] % 3 == 0:
                        M[i] //= 3
L = [25,8,75,12]

ChangeVal(L,4)

for i in L:
      print(i,end="#")

a. 5#8#15#4#
b. 5#8#5#4#
c. 5#8#15#14#
d. 5#18#15#4#

ANSWER:

b. 5#8#5#4#


Que 24. Suppose the content of ‘Myfile.txt’ is:

Humpty Dumpty sat on a wall
Humpty Dumpty had a great fall
All the king’s horses and all the king’s men
Couldn’t put Humpty together again

What will be the output of the following code?

myfile = open("Myfile.txt")
record = myfile.read().split()
print(len(record))
myfile.close()

a. 24
b. 25
c. 26
d. 27

ANSWER:

c. 26


Que 25. What will be the output of the following code?

Name="PythoN3.1"
R=""
for x in range(len(Name)):
      if Name[x].isupper():
             R = R + Name[x].lower()
      elif Name[x].islower():
             R = R + Name[x].upper()
      elif Name[x].isdigit():
             R = R + Name[x-1]
      else:
             R = R + "#"
print(R)

a. pYTHOn##@
b. pYTHOnN#@
c. pYTHOn#@
d. pYTHOnN@#

ANSWER:

b. pYTHOnN#@


Que 26. What will be the output of the following code?

x = 3
def myfunc():
       global x
       x += 2
       print(x, end=' ')

print(x, end=' ')
myfunc()
print(x, end=' ')

a. 3 3 3
b. 3 4 5
c. 3 3 5
d. 3 5 5

ANSWER:

d. 3 5 5


Que 27. What will be the output of the following code?

tup1 = (1,2,[1,2],3)
tup1[2][1]=3.14
print(tup1)

a. (1,2,[3.14,2],3)
b. (1,2,[1,3.14],3)
c. (1,2,[1,2],3.14)
d. Error Message

ANSWER:

b. (1,2,[1,3.14],3)


Que 28. Suppose the content of ‘Myfile.txt’ is:

Honesty is the best policy.

What will be the output of the following code?

myfile = open("Myfile.txt")
x = myfile.read()
print(len(x))
myfile.close()

a. 5
b. 25
c. 26
d. 27

ANSWER:

d. 27


Que 29. Suppose the content of ‘Myfile.txt’ is:

Culture is the widening of the mind and of the spirit.

What will be the output of the following code?

myfile = open("Myfile.txt")
x = myfile.read()
y = x.count('the')
print(y)
myfile.close()

a. 2
b. 3
c. 4
d. 5

ANSWER:

b. 3


Que 30. Suppose the content of ‘Myfile.txt’ is:

Ek Bharat Shreshtha Bharat

What will be the output of the following code?

myfile = open("Myfile.txt")
vlist = list("aeiouAEIOU")
vc=0
x = myfile.read()
for y in x:
     if(y in vlist):
           vc+=1
print(vc)
myfile.close()

a. 6
b. 7
c. 8
d. 9

ANSWER:

b. 7


Sorry! You cannot copy content of this page. Please contact, in case you want this content.

Scroll to Top