Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
575 views

Find The Output of Python Code - Qns

The document contains questions about predicting the output of Python code snippets. The questions cover topics like loops, functions, lists, dictionaries, files and more. Multiple choice options are given for each question to select the correct output.

Uploaded by

sanjhayprabu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
575 views

Find The Output of Python Code - Qns

The document contains questions about predicting the output of Python code snippets. The questions cover topics like loops, functions, lists, dictionaries, files and more. Multiple choice options are given for each question to select the correct output.

Uploaded by

sanjhayprabu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

PREDICTING OUTPUT BASED QUESTIONS

Que 1. Find the output of the given python code.


1 L.1 = [500, 800, 600, 200, 900]
2 START = 1
3 SUM = 0
4 for C in range(START,4):
5 SUM = SUM + L1[C]
6 print(C,":",SUM)
7 SUM = SUM + L1[0]*10
8 print(SUM)

Que 2. Select the correct output of the given python code.


1 a = "Year 2022 at All the best"
2 a = a.split('2')
3 b = a[0] + ". " + a[1] + ". " + a[3]
4 print (b)
(a) Year . 0. 0(b) Year 0. at All the best
(c) Year . 022. at All the best
(d) Year . 0. at all the best

Que 3. Write the output of the given python code.


1 >>> myexam="@@CBSE Examination 2022@@"
2 >>> print(myexam[::-2])

Que 4. Write the output of the given python code.


1 my_dict = {"name": "Aman", "age": 26}
2 my_dict['age'] = 27
3 my_dict['address'] = "Delhi"
4 print(my_dict.items())

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

Que 6. Predict the output of the Python code given below:


1 def Diff(N1, N2):
2 if N1>N2:
3 return N1-N2
4 else:
5 return N2-N1
6
7 NUM = [10,23,14,54,32]
8 for CNT in range (4,0,-1):
9 A = NUM[CNT]
10 B = NUM[CNT-1]
11
12 print(Diff(A,B), '#', end = ' ')
Que 7. Predict the output of the Python code given below:
1 tuple1 = (11, 22, 33, 44, 55 ,66)
2 list1 = list(tuple1)
3 new_list = []
4 for i in list1:
5 if i%2==0:
6 new_list.append(i)
7
8 new_tuple = tuple(new_list)
9
10 print(new_tuple)

Que 8. Write the output of the code given below:


1 p=5
2 def sum(q,r=2):
3 global p
4 p = r + q ** 2
5 print(p, end= '#')
6
7 a = 10
8 b=5
9 sum(a, b)
10 sum(r = 5, q = 1)

Que 9. Write the output of the code given below:


1 s = "welcome2cs"
2 n = len(s)
3 m = ""
4 for i in range(0, n):
5 if (s[i] >= 'a' and s[i] <= 'm'):
6 m = m + s[i].upper()
7 elif (s[i] >= 'n' and s[i] <= 'z'):
8 m = m +s[i-1]
9 elif (s[i].isupper()):
10 m = m + s[i].lower()
11 else:
12 m = m +'&'
13 print(m)

Que 10. Predict the output of the given Python code :


1 x = "apple, pear, peach"
2 y = x.split(", ")
3 for z in y :
4 print(z)

Que 11. Predict the output of the given Python code :


1 x = "apple, pear, peach, banana, grapes"
2 y = x.split(", ")
3 for z in y :
4 if z > 'f':
5 print(z.upper())
6 else:
7 print(z)
Que 12. Predict the output of the given Python code :
1 tup1= (10, 20, 30, 40, 50, 60, 70, 80, 90).
2 print (tup1 [3:7:2])
a. (40,50,60,70,80)
b. (40,50,60,70)
c. [40,60]
d. (40,60)

ANSWER:
d. (40,60)

Que 13. What is the output of the given Python code :


1 T=(100)
2 print(T*2)
a. Syntax error
b. (200,)
c. 200
d. (100,100)

Que 14. 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
What will be the output of the following code?
1 myfile = open("Myfile.txt")
2 data = myfile.readlines()
3 print(len(data))
4 myfile.close()
a. 3
b. 4
c. 5
d. 6

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


1 x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]]
2 y = x[1][2]
3 print(y)
a. 12.0
b. 13.0
c. 14.0
d. 15.0

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


1 x=2
2 while x < 9:
3 print(x, end='')
4 x=x+1
a. 12345678
b. 123456789
c. 2345678
d. 23456789
Que 17. Identify the output of the following Python statement :
1 b=1
2 for a in range(1, 10, 2):
3 b += a + 2
4 print(b)
a. 31
b. 33
c. 36
d. 39

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


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

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

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

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#

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

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#

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?
1 myfile = open("Myfile.txt")
2 record = myfile.read().split()
3 print(len(record))
4 myfile.close()
a. 24
b. 25
c. 26
d. 27
Que 25. What will be the output of the following code?
1 Name="PythoN3.1"
2 R=""
3 for x in range(len(Name)):
4 if Name[x].isupper():
5 R = R + Name[x].lower()
6 elif Name[x].islower():
7 R = R + Name[x].upper()
8 elif Name[x].isdigit():
9 R = R + Name[x-1]
10 else:
11 R = R + "#"
12 print(R)
a. pYTHOn##@
b. pYTHOnN#@
c. pYTHOn#@
d. pYTHOnN@#

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


1 x=3
2 def myfunc():
3 global x
4 x += 2
5 print(x, end=' ')
6
7 print(x, end=' ')
8 myfunc()
9 print(x, end=' ')
a. 3 3 3
b. 3 4 5
c. 3 3 5
d. 3 5 5

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


1 tup1 = (1,2,[1,2],3)
2 tup1[2][1]=3.14
3 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

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


Honesty is the best policy.
What will be the output of the following code?
1 myfile = open("Myfile.txt")
2 x = myfile.read()
3 print(len(x))
4 myfile.close()
a. 5
b. 25
c. 26
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?
1 myfile = open("Myfile.txt")
2 x = myfile.read()
3 y = x.count('the')
4 print(y)
5 myfile.close()
a. 2
b. 3
c. 4
d. 5

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


Ek Bharat Shreshtha Bharat
What will be the output of the following code?
1 myfile = open("Myfile.txt")
2 vlist = list("aeiouAEIOU")
3 vc=0
4 x = myfile.read()
5 for y in x:
6 if(y in vlist):
7 vc+=1
8 print(vc)
9 myfile.close()
a. 6
b. 7
c. 8
d. 9

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?
1 myfile = open("Myfile.txt")
2 line_count = 0
3 data = myfile.readlines()
4 for line in data:
5 if line[0] == 'T':
6 line_count += 1
7 print(line_count)
8 myfile.close()
a. 2
b. 3
c. 4
d. 5

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?
1 myfile = open("Myfile.txt")
2 data_rec = myfile.readlines()
3 myfile.close()
a. string
b. list
c. tuple
d. dictionary

Que 33. Write the output of the given Python code. [CBSE Board 2021]
1 D = {'Rno': 1, 'Name':'Suraj'}
2 print(D('Name'))

Que 34. What will be the output of the given code? [CBSE Board 2021]
1 L = ['ONE', 'TWO', 'THREE']
2 print(max(L))

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)

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 #

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)

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)

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&

Que 40. Write the output of the following Python code : [CBSE Board 2020]
1 for i in range(2,7,2):
2 print(i * '$')

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)

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)
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)

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 –

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 *

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)

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)

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)

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#

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)

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

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

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()

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

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#

You might also like