PyForSchool's Computer Science with Python Class XII 2023-24 [Revision Notes & Question Bank]

An outstanding 4.5 out of 5-star rating on Amazon!

Buy Now

Computer Science
Question Paper 2021-22
Term 1

SECTION - A

Question 1.Find the invalid identifier from the following

  1. name
  2. break
  3. section
  4. mark12

Question 2. Which of the following is a function/method of the pickle module?

  1. reader( )
  2. writer( )
  3. load( )
  4. read( )

Question 3. For a given declaration in Python as S = "WELCOME". Which of the following will be the correct output of print(S [1: :2])?

  1. WEL
  2. COME
  3. WLOE
  4. ECM

Question 4. Which of the following statement is not correct?

  1. We can write content into a text file opened using 'w' mode
  2. We can write content into a text file opened using 'w+' mode
  3. We can write content into a text file opened using 'r' mode
  4. We can write content into a text file opened using 'r+' mode

Question 5. Which of the following option is the correct Python statement to read and display the first 10 characters of a text file "Notes.txt"?

  1. F = open ('Notes.txt'); print(F.load(10))
  2. F = open ('Notes.txt'); print(F.dump(10))
  3. F = open ('Notes.txt'); print(F.read(10))
  4. F = open ('Notes.txt'); print(F.write(10))

Question 6. Which of the following is not a correct Python statement to open a text file "Notes.txt" to write content into it?

  1. F = open('Notes.txt', 'w')
  2. F = open('Notes.txt', 'a')
  3. F = open('Notes.txt', 'A')
  4. F = open('Notes.txt', 'w+')

Question 7. A text file opened using the following statement : MyFile = open('Notes.txt') Which of the following is the correct Python statement to close it?

  1. MyFile=close ('Notes.txt')
  2. MyFile.close('Notes.txt')
  3. close.MyFile()
  4. MyFile.close()

Question 8. Which of the following option is the correct usage for the tell( ) of a file objects?

  1. It places the file pointer at a desired offset in a file
  2. It returns the entire content of a file
  3. It returns the byte position of the file pointer as an integer
  4. It tells the details about the file

Question 9. Which of the following is an incorrect Logical operator in Python?

  1. not
  2. in
  3. or
  4. and

Question 10. Given the Python declaration S1 = "Hello". Which of the following statement will give an error?

  1. print(S1[4])
  2. S2=S1
  3. S1=S1[4]
  4. S1[4]="Y"

Question 11. Which of the following statement is incorrect in the context of pickled binary file?

  1. csv module is used for reading and writing objects in binary files.
  2. pickle module is used for reading and writing objects in binary files.
  3. load() of the pickle module is used to read objects
  4. dump() of the pickle module is used to write objects

Question 12. What is the significance of the seek() method?

  1. It seeks the absolute path of the file.
  2. It tells the current byte position of the file pointer within the file.
  3. It places the file pointer at a desired offset within the file.
  4. It seeks the entire content of the file.

Question 13. Which of the following is the correct expansion of csv?

  1. Comma Separated Values.
  2. Centrally Secured Values.
  3. Computerised Secured Values.
  4. Comma Secured Values.

Question 14. If the following statement is used to read the contents of a textfile object F:
X = F.readlines()
Which of the following is the correct data type of X?

  1. string
  2. list
  3. tuple
  4. dictionary

Question 15. Which of the following is not correct in context of Positional and Default parameters in Python functions?

  1. Default parameters must occur to the right of Positional parameters
  2. Positional parameters must occur to the right of Default parameters
  3. Positional parameters must occur to the left of Default parameters
  4. All parameters to the right of a Default parameter must also have Default values

Question 16. For a function header as follows :
def Calc(X, Y=20):
Which of the following funtion calls will give an Error?

  1. Calc(15, 25)
  2. Calc(X=15, Y=25)
  3. Calc(Y=25)
  4. Calc(X=25)

Question 17. Which of the following is not correct in context of scope of variables?

  1. global keyword is used to change value of a global variable in a local scope
  2. local keyword is used to change value of a local variable in a global scope
  3. global variable can be accessed without using the global keyword in a local scope
  4. local variables cannot be used outside its scope

Question 18. Which of the following is the default character for the newline parameter for a csv file object opened in write mode in Python IDLE?

  1. \n
  2. \t
  3. ,
  4. ;

Question 19. Which of the following is the correct output for the execution of the following Python statement?
print(5 + 3 ** 2 / 2)

  1. 32
  2. 8.0
  3. 9.5
  4. 32.0

Question 20. Which of the following is not a Tuple in Python?

  1. (1 , 2 , 3)
  2. ("One" , "Two" , "Three")
  3. (10 ,)
  4. ("One")

Question 21. Which of the following is not a funtion/method of the random module in Python?

  1. randfloat()
  2. randint()
  3. random()
  4. randrange()

Question 22. Which of the following is not a valid Python string operation?

  1. 'Welcome' + '10'
  2. 'Welcome' * 10
  3. 'Welcome' * 10.0
  4. "10" + 'Welcome'

Question 23. What will be the output for the following Python statements?

T = (10, 20, [30, 40, 50], 60, 70)
T[2] [1] = 100
print(T)

  1. (10, 20, 100, 60, 70)
  2. (10, 20, [30, 100, 50], 60, 70)
  3. (10, 20, [100, 40, 50], 60, 70)
  4. Errors

Question 24. What will be the output for the following Python statements?

L = [10, 20, 30, 40, 50]
L = L + 5
print(L)

  1. [10, 20, 30, 40, 50, 5]
  2. [15, 25, 35, 45, 55, 5]
  3. [5, 10, 20, 30, 40, 50]
  4. Error

Question 25. What will be the output for the following Python statements?

D = {"AMIT" : 90, "SUKHBIR" : 92, "JOHN" : 95}
print("JOHN" in D, 90 in D, sep = "#")

  1. True#False
  2. True#True
  3. False#True
  4. False#False

SECTION - B

Question 26. Nitish has declared a tuple T in Python as following :
T = (10 , 20 , 30)
Now , he wants to insert an element 40 after these three elements of T so that the tuple may contain (10 , 20 , 30 , 40)
Which of the following statement shall Nitish write to accomplish the above task?

  1. T = T + 40
  2. T = T + (40)
  3. T = T + (40,)
  4. Nitish cannot insert 40 into the tuple since Tuples are immutable

Question 27. Suppose the content of a text file Notes.txt is :
"The way to get started is to quit talking and begin doing"  
What will be the following Python code?

F = open("Notes.txt") 
F.seek(29) 
S = F.read() 
print(S)

  1. The way to get started is to
  2. quit talking and begin doing
  3. The way to get started is to quit talking and begin doing
  4. gniod nigeb dna gniklat tiuq ot si detrats teg ot yaw ehT

Question 28. Identify the output of the following Python statements

S = "GOOD MORNING"
print(S.capitalize(), S.title(), end = "!")

  1. GOOD MORNING ! Good morning
  2. Good morning ! Good morning
  3. Good morning ! Good Morning!
  4. Good morning Good Morning!

Question 29. Identify the output of the following Python statements

L = []
for i in range (4):
    L.append(2 * i + 1)
print (L[::-1])

  1. [7 , 5 , 3 , 1]
  2. [9 , 7 , 5 , 3]
  3. [4 , 3 , 2 , 1]
  4. [1 , 2 , 3 , 4]

Question 30. Identify the output of the following Python statements:

D = {}
T = ("ZEESHAN", "NISHANT", "GURMEET", "LISA")
for i in range(1, 5): 
    D[i] = T[i-1]
print(D)

  1. {"ZEESHAN", "NISHAN", "GURMEET", "LISA"}
  2. "ZEESHAN", "NISHAN", "GURMEET", "LISA"
  3. {[1, "ZEESHAN"], [2, "NISHANT"], [3, "GURMEET"], [4, "LISA"]}
  4. {1: "ZEESHAN", 2: "NISHAN", 3: "GURMEET", 4: "LISA"}

Question 31. Identify the output of the following statements

L1, L2 = [10, 15, 20, 25], []
for i in range (len(L1)):
    L2.insert(i, L1.pop())
print (L1, L2, sep="&")

  1. [ ] & [25, 20, 15, 10]
  2. [10, 15, 20, 25] & [25, 20, 15, 10]
  3. [10, 15, 20, 25] & [10, 15, 20, 25]
  4. [25, 20, 15, 10] & [ ]

Question 32. Which of the following Python modules is imported to store and retrieve objects using the process of serialization and deserialization?

  1. csv
  2. binary
  3. math
  4. pickle

Question 33. Which of the following function in used with the csv module in Python to read the contents of a csv file into an object?

  1. readrow()
  2. readrows()
  3. reader()
  4. load()

Question 34. What will be the output of the following Python code?

S = "WELCOME"
def Change(T): 
    T = "HELLO"
    print(T, end = '@')
Change(S)
print(S)
  1. WELCOME@HELLO
  2. HELLO@HELLO
  3. HELLO@WELCOME
  4. WELCOME@WELCOME

Question 35. Identify the correct possible output for the following Python code :

import random
for N in range (2, 5, 2):
    print(random.randrange(1,N), end="#")
  1. 1#3#5#
  2. 2#3#
  3. 1#4#
  4. 1#3#

Question 36. What will be the output of the following Python code?

def FunStr(S):
    T = ""
    for i in S:
        if i.isdigit():
            T = T + i
    return T 
X = "PYTHON 3.9"
Y = FunStr(X)
print (X, Y, sep = "*")
  1. PYTHON 3.9
  2. PYTHON 3.9*3.9
  3. PYTHON 3.9*39
  4. ERROR

Question 37. What will be the output of the following Python code?

V = 50
def Change(N):
    global V
    V, N = N, V
    print(V, N, sep="#", end="@")
Change(20)
print(V)
  1. 20#50@20
  2. 50@20#50
  3. 50#50#50
  4. 20@50#20

Question 38. Which of the following option can be the output for the following Python code?

L1 = [10, 20, 30, 20, 10]
L2 = []
for i in L1:
    if i not in L2:
        L2.append(i)
print(L1, L2, sep ="&")
  1. [10, 20, 30, 20, 10]&[10, 20, 30, 20, 10]
  2. [10, 20, 30, 20, 10] [10, 20, 30, 20, 10] &
  3. [10, 20, 30, 20, 10]&[30, 20, 10]
  4. [10, 20, 30, 20, 10]&[10, 20, 30]

Question 39. What is the output of the following Python code?

def ListChange():
    for i in range(len(L)):
        if L[i] % 2 == 0:
            L[i] = L[i] * 2
        if L[i] % 3 == 0:
            L[i] = L[i] * 3
        else:
            L[i] = L[i] * 5
L = [2,6, 9, 10]
ListChange()
for i in L:
    print(i, end = "#")
  1. 4#12#27#20#
  2. 6#18#27#50#
  3. 20#36#27#100#
  4. Error

Question 40. Suppose the content of a text file "Rhymes.txt" is as follows:
Jack & Jill
went up the hill
What will be the output of the following Python code?

F = open("Rhymes.txt")
L = F.readlines()
for i in L:
    S = i.split()
    print(len(S), end = "#")
  1. 2#4#
  2. 3#4#
  3. 2#
  4. 7#

Question 41. Identify the output of the following Python code

D = {1: "one", 2: "Two", 3: "Three"}
L = []
for K, V in D.items ():
    if V [0] == "T":
        L.append(K)
Print(L)
  1. [1, 2, 3]
  2. ["One", "Two", "Three"]
  3. [2, 3]
  4. ["Two", "Three"]

Question 42. Suppose the content of "Rhymes.txt" is:
Baa baa black sheep,
have you any wool?
What will be the output of the following Python code?

F = open ("Rhymes.txt")
S = F.read()
L = S.split()
for i in L:
    if len(i) %3 != 0:
        print (i, end = " ")
  1. Baa baa you any
  2. Black have wool?
  3. Black sheep, have wool?
  4. Error

Question 43. Suppose the content of "Rhymes.txt" is
One, two, three, four, five
Once I caught a fish alive.
What will be the output of the following Python code?

F = open ("Rhymes.txt")
S = F.read()
print(S.count ('e', 20))
  1. 20
  2. 1
  3. 3
  4. 6

Question 44. What will be the output of the following Python code?

V = 25
def Fun(ch):
    V = 50
    print(V, end=ch)
    V *= 2
    print(V, end=ch)
print (V, end = "*")
Fun ("!")
print(V)
  1. 25*50!100!25
  2. 50*100!100!100
  3. 25*50!100!100
  4. Error

Question 45. Suppose the content of "Rhymes.txt" is
Good Morning Madam
What will be the output of the following Python code?

F = open("Rhymes.txt")
L = F.read().split()
for W in L:
    if W.lower() == W [::-1].lower():
        print(W)
  1. Good
  2. Morning
  3. Madam
  4. Error

Question 46. Suppose the content of "Rhymes.txt" is
Hickory Dickory Dock
The mouse went up the clock
What will be the output of the following Python code?

F = open("Rhymes.txt")
L = F.readlines()
X = ["the", "ock"]
for i in L:
    for W in i.split():
        if W in X:
            print (W, end = "*")
  1. the*
  2. Dockthetheclock
  3. Docktheclock*
  4. Error

Question 47. Consider the following directory structure

Suppose the present working directory is MyCompany. What will be the relative path of the file Transactions.Dat?

  1. MyCompany/Transactions.Dat
  2. MyCompany/Accounts/Transactions.Dat
  3. Accounts/Transactions.Dat
  4. ../Transactions.Dat

Question 48. What will be the output of the following Python code?

S = "UVW"; L = [10, 20, 30]; D = {}
N=len(S)
for I in range(N):
    D [L[I]] = S[I]
for K, V in D.items():
       print (K, V, sep="*", end=",")
  1. U*10,V*20,W*30,
  2. 10*U,20*V,30*W,
  3. 10,20,30,U*V*W*
  4. Error

Question 49. What will be the output of the following Python code?

L = [10, 20]
L1 = [30, 40]
L2 = [50, 60]
L.append(L1)
L.extend(L2)
print(L)
  1. [60, 50, 40, 30, 20, 10]
  2. [10, 20, 30, 40, 50, 60]
  3. [10, 20, 30, 40, [50, 60]]
  4. [10, 20, [30, 40], 50, 60]

SECTION - C

Nisha, an intern in ABC Pvt, Ltd., is developing a project using the csv module in Python Nisha, an intern in ABC Pvt, Ltd., is developing a project using the csv module in Python. She has partially developed the code as follows leaving out statements about which she is not very confident. The code also contains errors in certain statements. Help her in completing the code to read the desired csv File named "Employee.csv"

CSV File content
ENO, NAME, DEPARTMENT
E1, ROSHAN SHARMA, ACCOUNTS
E2, AASMA KHALID, PRODUCTION
E3, AMRIK GILL, MARKETING
E4, SARAH WILLIAMS, HUMAN RESOURCE

Incomplete code with Errors

import CSV #statement-1
with open (____, ____, newline= ' ') as File: #statement-2
    ER = csv.____ #statement-3
    for R in range(ER): #statement-4
        if ____ == "ACCOUNTS": #statement-5
            print(____, ____) #statement-6

Question 50. Nisha gets an Error for the module name used in Statement-1. What should she write in place of CSV to import the correct module?

  1. file
  2. csv
  3. Csv
  4. pickle

Question 51. identify the missing code for blank spaces in the line marked as statement-2 to open the mentioned file.

  1. "Employee.csv", "r"
  2. "Employee.csv", "w"
  3. "Employee.csv", "rb"
  4. "Employee.csv", "wb"

Question 52. Choose the function name (with parameter) that should be used in the line marked as statement-3

  1. reader(File)
  2. readrows(File)
  3. writer(File)
  4. writerows(File)

Question 53. Nisha gets an erroe in statement-4. What should she write to correct the statement?

  1. for R in ER:
  2. while R in range(ER):
  3. for R = ER:
  4. while R == ER:

Question 54. Identify the suitable code for blank space in Statement-5 to match every row's 3rd property with "ACCOUNTS".

  1. ER[3]
  2. R[2]
  3. ER[2]
  4. R[3]

Question 55. Identify the suitable code for blank space in statement-6 to display every Employee's name and corresponding Department?

  1. ER[1], R[2]
  2. R[1], ER [2]
  3. R[1], R[2]
  4. ER[1],ER[2]