Find the output of Python Code - Ans
Find the output of Python Code - Ans
ANSWER:
1 : 800
5800
2 : 6400
11400
3 : 11600
16600
ANSWER:
@20 otnmx SC@
ANSWER:
dict_items([('name', 'Aman'), ('age', 27), ('address', 'Delhi')])
Que 5. Find and write the output of the following python code:
1 for Name in ['Jayes', 'Ramya', 'Taruna', 'Suraj'] :
2 print (Name)
3 if Name[0] == 'T' :
4 break
5 else :
6 print ('Finished!')
7 print ('Got it!')
ANSWER:
Jayes
Finished!
Ramya
Finished!
Taruna
Got it!
ANSWER:
22 # 40 # 9 # 13 #
ANSWER:
(22, 44, 66)
ANSWER:
105#6#
ANSWER:
sELCcME&Cc
ANSWER:
apple
pear
peach
ANSWER:
apple
PEAR
PEACH
banana
GRAPES
ANSWER:
d. (40,60)
ANSWER:
c. 200
ANSWER:
b. 4
ANSWER:
d. 15.0
ANSWER:
c. 2345678
ANSWER:
c. 36
ANSWER:
b. 3
Que 19. What will be the output of the following Python code?
1 def add (num1, num2):
2 sum = num1 + num2
3
4 sum = add(20,30)
5 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?
1 def my_func(var1=100, var2=200):
2 var1 += 10
3 var2 = var2 - 10
4 return var1+var2
5
6 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?
1 value = 50
2 def display(N):
3 global value
4 value = 25
5 if N%7 == 0:
6 value = value + N
7 else:
8 value = value - N
9
10 print(value, end="#")
11
12 display(20)
13
14 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?
1 import random
2
3 List=["Delhi","Mumbai","Chennai","Kolkata"]
4
5 for y in range(4):
6 x = random.randint(1,3)
7 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]
1 def ChangeVal(M,N):
2 for i in range(N):
3 if M[i] % 5 == 0:
4 M[i] //= 5
5 if M[i] % 3 == 0:
6 M[i] //= 3
7 L = [25,8,75,12]
8
9 ChangeVal(L,4)
10
11 for i in L:
12 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#
ANSWER:
c. 26
ANSWER:
b. pYTHOnN#@
ANSWER:
d. 3 5 5
ANSWER:
b. (1,2,[1,3.14],3)
ANSWER:
d. 27
ANSWER:
b. 3
ANSWER:
b. 7
ANSWER:
a. 2
ANSWER:
b. list
Que 33. Write the output of the given Python code. [CBSE Board 2021]
1 D = {'Rno': 1, 'Name':'Suraj'}
2 print(D('Name'))
ANSWER:
Suraj
Que 34. What will be the output of the given code? [CBSE Board 2021]
1 L = ['ONE', 'TWO', 'THREE']
2 print(max(L))
ANSWER:
TWO
Que 35. What shall be the output for the execution of the following Python Code? [CBSE
Board 2021]
1 Cities = ['Delhi', 'Mumbai']
2 Cities[0], Cities[1] = Cities[1], Cities[0]
3 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]
1 import random
2 Signal = [ 'Stop', 'Wait', 'Go' ]
3 for K in range(2, 0, -1):
4 R = randrange(K)
5 print (Signal[R], end = ' # ')
(a) Stop # Wait # Go #
(b) Wait # Stop #
(c) Go # Wait #
(d) Go # Stop #
ANSWER:
(b) Wait # Stop #
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]
1 def Change(A):
2 S=0
3 for i in range(len(A)//2):
4 S += (A[i] * 2)
5 return S
6
7 B = [10,11,12,30,32,34,35,38,40,2]
8
9 C = Change(B)
10
11 print('Output is', C)
ANSWER:
Output is 190
Que 38. Write the output for the execution of the following Python Code. [CBSE Board
2020]
1 def Call(P = 40, Q = 20):
2 P=P+Q
3 Q=P–Q
4 print(P, '@', Q)
5 return P
6
7 R = 200
8 S = 100
9 R = Call(R, S)
10 print (R, '@', S)
11 S = Call(S)
12 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]
1 import random
2 Colours = ["VIOLET","INDIGO","BLUE","GREEN", "YELLOW","ORANGE","RED"]
3 End = randrange(2)+3
4 Begin = randrange(End)+1
5 for i in range(Begin,End):
6 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&
Que 40. Write the output of the following Python code : [CBSE Board 2020]
1 for i in range(2,7,2):
2 print(i * '$')
ANSWER: Output is
$$
$$$$
$$$$$$
Que 41. Write the output of the following Python code : [CBSE Board 2020]
1 def Update(X=10):
2 X += 15
3 print('X = ', X)
4
5 X = 20
6 Update()
7 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]
1 Msg1="WeLcOME"
2 Msg2="GUeSTs"
3 Msg3=""
4
5 for I in range(0,len(Msg2)+1):
6 if Msg1[I]>="A" and Msg1[I]<="M":
7 Msg3=Msg3+Msg1[I]
8 elif Msg1[I]>="N" and Msg1[I]<="Z":
9 Msg3=Msg3+Msg2[I]
10 else:
11 Msg3=Msg3+"*"
12
13 print(Msg3)
ANSWER: Output is
G*L*TME
Que 43. Find and write the output of the following Python code : [CBSE Board 2019]
1 def Changer(P,Q=10):
2 P=P/Q
3 Q=P%Q
4 print(P,"#",Q)
5 return P
6
7 A=200
8 B=20
9
10 A=Changer(A,B)
11 print(A,"$",B)
12 B=Changer(B)
13 print(A,"$",B)
14 A=Changer(A)
15 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]
1 import random
2
3 VALUES=[10,20,30,40,50,60,70,80]
4
5 BEGIN = random.randint(1, 3)
6 LAST = random.randint(BEGIN, 4)
7
8 for I in range(BEGIN, LAST+1):
9 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 -
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]
1 import random
2
3 VAL=[80, 70, 60, 50, 40, 30, 20, 10]
4
5 Start = random.randint(1, 3)
6 End = random.randint(Start, 4)
7
8 for I in range(Start, End+1):
9 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
Que 46. Find and write the output of the following Python code : [CBSE Board 2019
Compartment]
1 def Alter(P=15,Q=10):
2 P=P*Q
3 Q=P/Q
4 print(P, "#", Q)
5 return Q
6
7 A = 100
8 B = 200
9 A = Alter(A, B)
10 print (A, "$", B)
11 B = Alter(B)
12 print (A, "$", B)
13 A = Alter(A)
14 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]
1 Str1 = "EXAM2018"
2 Str2 = ""
3 I=0
4
5 while I < len(Str1):
6 if Str1[I] >= "A" and Str1[I] <= "M":
7 Str2 = Str2 + Str1[I+1]
8 elif Str1[I] >= "0" and Str1[I] <= "9":
9 Str2 = Str2 + Str1[I-1]
10 else:
11 Str2 = Str2 + "*"
12 I=I+1
13
14 print(Str2)
ANSWER: Output is
X*M2M201
Que 48. Find and write the output of the following Python code : [CBSE Board 2018]
1 Data = ["P",20,"R",10,"S",30]
2 Times = 0
3 Alpha = ""
4 Add = 0
5 for C in range(1,6,2):
6 Times = Times + C
7 Alpha = Alpha + Data[C-1]+ "$"
8 Add = Add + Data[C]
9 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]
1 import random
2
3 POINTS = [30,50,20,40,45];
4
5 BEGIN = random.randint(1, 3)
6 LAST = random.randint(2, 4)
7
8 for C in range(BEGIN, LAST+1):
9 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#
Que 50. Find and write the output of the following Python code : [CBSE Board 2018
COMPARTMENT]
1 Val = [20,"A",40,"K",10,"H"]
2 Freq = 0
3 Sum = 0
4 Cat = ""
5 for I in range(1,6,2):
6 Freq = Freq + I
7 Sum = Sum + Val[I-1]
8 Cat = Cat + Val[I] + "*"
9 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]
1 TXT = ["20", "50", "30", "40"]
2 CNT = 3
3 TOTAL = 0
4 for C in [7, 5, 4, 6]:
5 T = TXT[CNT]
6 TOTAL = float (T) + C
7 print(TOTAL)
8 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 ]
1 import random
2
3 NAV = ["LEFT", "FRONT", "RIGHT", "BACK"]
4
5 NUM = random.randint(1,3)
6 NAVG = ""
7
8 for C in range (NUM, 1, -1):
9 NAVG = NAVG + NAV[C]
10
11 print(NAVG)
(i) BACKRIGHT
(ii) BACKRIGHTFRONT
(iii) BACK
(iv) LEFTFRONTRIGHT
ANSWER:
Possible Outputs:-
(i) BACKRIGHT
Que 53. Find and write the output of the following Python code : [CBSE Board 2016]
1 Values = [10, 20, 30, 40]
2 for Val in Values:
3 for I in range(1, Val % 9) :
4 print(I, "*", end = " ")
5 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]
1 for Name in ['John', 'Garima','Seema','Karan']:
2 print(Name)
3 if Name[0]=='S':
4 break
5 else:
6 print('Completed!')
7 print('Weldone!')
ANSWER: Output is
John
Completed!
Garima
Completed!
Seema
Weldone!
Que 55. Find and write the output of the following Python code :
1 myTuple = ("John", "Peter", "Vicky")
2
3 x = "#".join(myTuple)
4
5 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