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)
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)
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)
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#
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)
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
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
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()
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!')
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#