Anjeev Singh Academy

Anjeev Singh Academy

50+ Find the output of Python Code important questions

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

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

def Alter(P=15,Q=10):
     P = P * Q
     Q = P / Q
     print(P, "#", Q)
     return Q

A = 100
B = 200
A = Alter(A, B)
print (A, "$", B)
B = Alter(B)
print (A, "$", B)
A = Alter(A)
print (A, "$", B)

ANSWER: Output is

20000 # 100.0
100.0 $ 200
2000 # 200.0
100.0 $ 200.0
1000.0 # 100.0
100.0 $ 200.0


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

Str1 = "EXAM2018"
Str2 = ""
I = 0

while I < len(Str1):
     if Str1[I] >= "A" and Str1[I] <= "M":
          Str2 = Str2 + Str1[I+1]
     elif Str1[I] >= "0" and Str1[I] <= "9":
          Str2 = Str2 + Str1[I-1]
     else:
          Str2 = Str2 + "*"
     I = I + 1

print(Str2)

ANSWER: Output is

X*M2M201


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

Data = ["P",20,"R",10,"S",30]
Times = 0
Alpha = ""
Add = 0
for C in range(1,6,2):
     Times = Times + C
     Alpha = Alpha + Data[C-1]+ "$"
     Add = Add + Data[C]
     print(Times, Add, Alpha)

ANSWER: Output is

1 20 P$
4 30 P$R$
9 60 P$R$S$


Que 49. 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 maximum values that can be assigned to the variable BEGIN and LAST. [CBSE Board 2018]

import random

POINTS = [30,50,20,40,45];

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

for C in range(BEGIN, LAST+1):
       print(POINTS[C], "#",)

(i) 20#50#30#
(ii) 20#40#45#
(iii) 50#20#40#
(iv) 30#50#20#

ANSWER:

Possible Outputs:-

(iii) 50#20#40#


Maximum Value of BEGIN = 3
Maximum value of LAST = 4


Que 50. Find and write the output of the following Python code : [CBSE Board 2018 COMPARTMENT]

Val = [20,"A",40,"K",10,"H"]
Freq = 0
Sum = 0
Cat = ""
for I in range(1,6,2):
     Freq = Freq + I
     Sum = Sum + Val[I-1]
     Cat = Cat + Val[I] + "*"
     print(Freq, Sum, Cat)

ANSWER: Output is

1 20 A*
4 60 A*K*
9 70 A*K*H*


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

TXT = ["20", "50", "30", "40"]
CNT = 3
TOTAL = 0
for C in [7, 5, 4, 6]:
     T = TXT[CNT]
     TOTAL = float (T) + C
     print(TOTAL)
     CNT -= 1

ANSWER: Output is

47.0
35.0
54.0
26.0


Que 52. What are the possible output(s) executed from the following code? Also specify the maximum and minimum values that can be assigned to the variable NUM. [CBSE Board 2017 ]

import random

NAV = ["LEFT", "FRONT", "RIGHT", "BACK"]

NUM = random.randint(1,3)
NAVG = ""

for C in range (NUM, 1, -1):
        NAVG = NAVG + NAV[C]

print(NAVG)

(i) BACKRIGHT
(ii) BACKRIGHTFRONT
(iii) BACK
(iv) LEFTFRONTRIGHT

ANSWER:

Possible Outputs:-

(i) BACKRIGHT


Maximum Value of NUM = 3
Minimum value of NUM = 1


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

Values = [10, 20, 30, 40]
for Val in Values:
     for I in range(1, Val % 9) :
          print(I, "*", end = " ")
     print()

ANSWER: Output is

1 * 
1 * 2 * 
1 * 2 * 3 * 


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

for Name in ['John', 'Garima','Seema','Karan']:
     print(Name)
     if Name[0]=='S':
          break
     else:
          print('Completed!')
print('Weldone!')

ANSWER: Output is

John
Completed!
Garima
Completed!
Seema
Weldone!


Que 55. Find and write the output of the following Python code :

myTuple = ("John", "Peter", "Vicky")

x = "#".join(myTuple)

print(x)

(a) #John#Peter#Vicky
(b) John#Peter#Vicky
(c) John#Peter#Vicky#
(d) #John#Peter#Vicky#

ANSWER: Output is

(b) John#Peter#Vicky


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

Scroll to Top