Anjeev Singh Academy

50+ Find the output of Python Code important questions

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

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

Twinkle twinkle little star
How I wonder what you are
Up above the world so high
Like a diamond in the sky
Twinkle twinkle little star

What will be the output of the following code?

myfile = open("Myfile.txt")
line_count = 0
data = myfile.readlines()
for line in data:
      if line[0] == 'T':
              line_count += 1
print(line_count)
myfile.close()

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

ANSWER:

a. 2


Que 32. Assume the content of ‘student.txt’ is:

Arjun Kumar
Ismail Khan
Joseph B
Hanika Kiran

What will be the data type of data_rec?

myfile = open("Myfile.txt")
data_rec = myfile.readlines()
myfile.close()

a. string
b. list
c. tuple
d. dictionary

ANSWER:

b. list


Que 33. Write the output of the given Python code. [CBSE Board 2021]

D = {'Rno': 1, 'Name':'Suraj'}
print(D('Name'))

ANSWER:

Suraj


Que 34. What will be the output of the given code? [CBSE Board 2021]

L = ['ONE', 'TWO', 'THREE']
print(max(L))

ANSWER:

TWO


Que 35. What shall be the output for the execution of the following Python Code? [CBSE Board 2021]

Cities = ['Delhi', 'Mumbai']
Cities[0], Cities[1] = Cities[1], Cities[0]
print(Cities)

ANSWER:

['Mumbai', 'Delhi']


Que 36. What possible output(s) is/are expected to be displayed on the screen at the time of execution of the program from the following code?
Also, specify the maximum and minimum value that can be assigned to the variable R when K is assigned value as 2.
[CBSE Board 2021]

import random
Signal = [ 'Stop', 'Wait', 'Go' ]
for K in range(2, 0, -1):
      R = randrange(K)
      print (Signal[R], end = ' # ')

(a) Stop # Wait # Go #
(b) Wait # Stop #
(c) Go # Wait #
(d) Go # Stop #

ANSWER:

(b) Wait # Stop #

When K is assigned value as 2

Maximum value of R = 1

Minimum value of R = 0


Que 37. Write the output for the execution of the following Python Code. [CBSE Board 2021]

def Change(A):
      S=0
      for i in range(len(A)//2):
               S  += (A[i] * 2)
      return S

B = [10,11,12,30,32,34,35,38,40,2]

C = Change(B)

print('Output is', C)

ANSWER:

Output is 190


Que 38. Write the output for the execution of the following Python Code. [CBSE Board 2020]

def Call(P = 40, Q = 20):
      P = P + Q
      Q = P – Q
      print(P, '@', Q)
      return P

R = 200
S = 100
R = Call(R, S)
print (R, '@', S)
S = Call(S)
print(R, '@', S)

ANSWER:

300 @ 200
300 @ 100
120 @ 100
300 @ 120


Que 39. What is possible output(s) expected to be displayed on screen at the time of execution of the program from the following code ? Also specify the minimum and maximum values that can be assigned to the variable End. [CBSE Board 2020]

import random
Colours = ["VIOLET","INDIGO","BLUE","GREEN", "YELLOW","ORANGE","RED"]
End = randrange(2)+3
Begin = randrange(End)+1
for i in range(Begin,End):
        print(Colours[i],end="&")

(i) INDIGO&BLUE&GREEN&
(ii) VIOLET&INDIGO&BLUE&
(iii) BLUE&GREEN&YELLOW&
(iv) GREEN&YELLOW&ORANGE&

ANSWER:

Possible Outputs:-

(i) INDIGO&BLUE&GREEN& 
(iii) BLUE&GREEN&YELLOW& 


Minimum Value of End = 3
Maximum value of End = 4


Que 40. Write the output of the following Python code : [CBSE Board 2020]

for i in range(2,7,2):
       print(i * '$')

ANSWER: Output is

$$
$$$$
$$$$$$


Que 41. Write the output of the following Python code : [CBSE Board 2020]

def Update(X=10):
       X += 15
       print('X = ', X)

X = 20
Update()
print('X = ', X)

ANSWER: Output is

X = 25
X = 20


Que 42. Find and write the output of the following Python code : [CBSE Board 2019]

Msg1="WeLcOME"
Msg2="GUeSTs"
Msg3=""

for I in range(0,len(Msg2)+1):
     if Msg1[I]>="A" and Msg1[I]<="M":
          Msg3=Msg3+Msg1[I]
     elif Msg1[I]>="N" and Msg1[I]<="Z":
          Msg3=Msg3+Msg2[I]
     else:
          Msg3=Msg3+"*"

print(Msg3)

ANSWER: Output is

G*L*TME


Que 43. Find and write the output of the following Python code : [CBSE Board 2019]

def Changer(P,Q=10):
     P = P / Q
     Q = P % Q
     print(P,"#",Q)
     return P

A=200
B=20

A=Changer(A,B)
print(A,"$",B)
B=Changer(B)
print(A,"$",B)
A=Changer(A)
print(A,"$",B)

ANSWER: Output is

10.0 # 10.0
10.0 $ 20
2.0 # 2.0
10.0 $ 2.0
1.0 # 1.0
1.0 $ 2.0


Que 44. What is possible output(s) expected to be displayed on the screen at the time of execution of the program from the following code? Also, specify the minimum values that can be assigned to the variable BEGIN and LAST. [CBSE Board 2019]

import random

VALUES=[10,20,30,40,50,60,70,80]

BEGIN = random.randint(1, 3)
LAST = random.randint(BEGIN, 4)

for I in range(BEGIN, LAST+1):
        print(VALUES[I], "-",)

(i) 30 – 40 – 50 –
(ii) 10 – 20 – 30 – 40 –
(iii) 30 – 40 – 50 – 60 –
(iv) 30 – 40 – 50 – 60 – 70 –

ANSWER:

Possible Outputs:-

(i) 30 - 40 - 50 - 


Minimum Value of BEGIN = 1
Minimum value of LAST = 1


Que 45. What is possible output(s) expected to be displayed on the screen at the time of execution of the program from the following code? Also, specify the minimum values that can be assigned to the variable Start and End. [CBSE Board 2019 Compartment]

import random

VAL=[80, 70, 60, 50, 40, 30, 20, 10]

Start = random.randint(1, 3)
End = random.randint(Start, 4)

for I in range(Start, End+1):
         print(VAL[I], "*", )

(i) 40 * 30 * 20 * 10 *
(ii) 70 * 60 * 50 * 40 * 30 *
(iii) 50 * 40 * 30 *
(iv) 60 * 50 * 40 *

ANSWER:

Possible Outputs:-

(iv) 60 * 50 * 40 * 


Minimum Value of Start = 1
Minimum value of End = 1


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

Scroll to Top