Computer Science-Class-Xii-Sample Question Paper-1
Computer Science-Class-Xii-Sample Question Paper-1
CLASS XII
COMPUTER SCIENCE (083)
TERM I
Maximum Marks: 35 Time Allowed: 90 Minutes
General Instructions:
1. The question paper is divided into 3 Sections – A, B and C.
2. Section A consists of 25 Questions (1-25). Attempt any 20 questions.
3. Section B consists of 24 Questions (26-49). Attempt any 20 questions.
4. Section C consists of 6 case study based questions (50-55). Attempt any 5 questions.
5. All questions carry equal marks.
Section A
This section consists of 25 Questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
1. In Python, the terms ‘global’, ‘else’ and ‘pass’ are used to refer to:
(i) Literals (ii) Keywords
(iii) Variables (iv) Punctuators
2. Take these numbers into consideration: 2,5,6,3,5,2,1,7. Write a command that declares a tuple named A
with these integers as elements.
(i) A = (2,5,6,3,5,2,1,7) (ii) A = 2,5,6,3,5,2,1,7
(iii) A = {2,5,6,3,5,2,1,7} (iv) A = [2,5,6,3,5,2,1,7]
3. Given a tuple Tup1=(25,35,43,22,13,56,45,78,90)
Identify the statement from the list below that will produce the result as (25,43,13,45,90)
(i) print(Tup1[::]) (ii) print(Tup1[0:9:1])
(iii) print(Tup1[::2]) (iv) print(Tup1[2:0:9])
4. Which of the following statements is correct regarding file access modes?
(i) In ‘r’ mode, we can read and write data from/in the file.
(ii) In ‘a’ mode, the existing data will be over-written if the file exists.
(iii) In ‘w’ mode, the data in the file is retained and new data will be appended to the end.
(iv) In ‘a+’ mode, both reading and writing operations can take place and new data is appended to the end
of the existing file.
5. Which of the following options can be used to read the first five characters of a text file ‘Poem.txt’ from
the file object File1?
(i) File1.read(4) (ii) File1.readlines(5)
(iii) File1.read(5) (iv) File1.read(6)
6. Consider a statement
fileobj = open(“myblog.txt”, ‘r’)
Sample Question Paper 1
Which of the following options can be used to print the last line of a text file ‘myblog.txt’?
(i) print(fileobj.readlines() -1)
(ii) disp = fileobj.readlines()
print(disp[-1])
(iii) print(fileobj.readlines(-1))
(iv) print(fileobj.read(-1))
A.1
7. Which of the following statements is used to open a text file to add new contents at the end of the
already existing text file named ‘mydiary.txt’?
(i) with open(“’mydiary.txt”, ‘w’) as fileobj:
(ii) fileobj = open(“mydiary.txt”, ‘a’)
(iii) with open(“mydiary.txt”,’a’) as fileobj:
(iv) with open(“mydiary”, ‘r+’) as fileobj:
(a) Only (i)
(b) Only (ii)
(c) Both (ii) and (iii)
(d) Both (i) and (iv)
8. Write the output of the following code snippet.
x = ‘Rain’
z = 3
print(len(x) * z)
(i) 10 (ii) RainRainRain
(iii) 12 (iv) 3 3 3
9. Fill in the blanks with the appropriate operator to obtain the output.
31 ……… 3 = 10
(i) / (ii) %
(iii) // (iv) ^
10. Consider a tuple T1=(2,3,{1:‘One’,2:‘Two’,3:‘Three’}). Identify the statement that will result
in an error.
(i) print(T1[3]) (ii) print(T1[0])
(iii) print(2 in T1) (iv) print(len(T1))
11. “The information is stored in machine-readable format and pickle module is used for reading and writing
data from/in the file.”
Identify the type of file discussed in the above lines?
(i) Text files (ii) CSV files
(iii) Binary file (iv) All of the above
12. Assume that you are writing in a text file; now you want to identify where the cursor is currently at in the
file. Which function will you use for the same?
(i) seek() (ii) hide()
(iii) tell() (iv) type()
13. Identify which function is used to write data in the binary file?
(i) seek() (ii) load()
(iii) dump() (iv) write()
14. Consider the statements given below:
Fileobj = open(“Report.txt”, ‘r’)
Computer Science with Python–XII
Fileobj.seek(25,0)
Choose the statement that best explains the second statement.
(i) It will place the pointer at 25 bytes ahead of the current file pointer position.
(ii) It will place the pointer at 25 bytes behind from the end-of file.
(iii) It will place the pointer at 25 bytes from the beginning of the file.
(iv) It returns 25 characters from the 0th index.
15. Identify the incorrect statement regarding passing parameters to functions.
(i) You can pass keyword arguments in any order.
(ii) You can pass positional argument in any order.
(iii) You can pass both positional and keyword arguments together.
(iv) An argument list must have any positional arguments followed by any keyword arguments.
A.2
16. Identify the incorrect statement regarding declaration of default parameters in function header.
(i) def Total_Amt(cost = 200, qty,disc= 0.2):
(ii) def Total_Amt(cost= 200, qty=20, disc):
(iii) def Total_Amt(cost, qty=20,disc=0.2):
(iv) def Total_Amt(cost, qty=20, disc):
(a) Only (ii)
(b) Both (ii) and (iii)
(c) Both (i) and (iii)
(d) Both (ii) and (iv)
17. Consider a function
def Cal_cube(n):
Which of the following function call can be used to invoke the given function definition?
(i) Calc_cube(5): (ii) Calc_cube()
(iii) Calc_cube(5) (iv) Calc_cube(5,5,5)
18. Which of the following functions forces the writing of data on disc which is still pending in the output
buffer?
(i) read() (ii) save()
(iii) flush() (iv) load()
19. Which of the following statements is correct regarding csv.writer() object for storing data in the
csv file?
(i) Removes the delimiter characters from the data before storing it.
(ii) Returns a writer object which writes data into CSV file.
(iii) Creates rows
(iv) Creates columns
20. Which of the following is the default delimiter character in CSV file?
(i) / (ii) ,
(iii) : (iv) %
21. Which of the following groups of functions belongs to CSV module?
(i) reader(), writer() (ii) readlines(), writelines()
(iii) writerow(), read() (iv) writer(), readline()
22. In which mode are Python instructions stored in a file with .py extension?
(i) Script mode
(ii) Run mode
(iii) Interactive mode
(iv) All of these
23. Which of the following statements is considered as multiline comment?
(i) /* Program to calculate Simple Interest. */
(ii) #Program to calculate
Simple Interest
(iii) ’’’Program to calculate
Simple Interest ’’’
Sample Question Paper 1
Section B
This section consists of 24 Questions (26 to 49). Attempt any 20 questions.
26. What is the correct declaration of a tuple P to obtain the following output?
p = …………………
print(p*2)
Output: (240, 240)
(i) (240) (ii) “240”
(iii) (240,) (iv) (120)
27. Consider a file “myrhymes.txt”
If you’re happy and you know it, clap your hands (clap clap)
If you’re happy and you know it, clap your hands (clap clap)
If you’re happy and you know it, and you really want to show it.
If you’re happy and you know it, clap your hands (clap clap)
What will be the output of the following code?
fileobj=open('myrhymes.txt','r')
count = 0
l=fileobj.read()
word= l.split()
for i in word:
if(i=='clap'):
count=count+1
print(count)
fileobj.close()
(i) 9 (ii) 6
(iii) 3 (iv) 4
28. Identify the output of the following Python statements.
L1= [[‘Red’,’Green’],[‘Blue’,‘Yellow’,‘Orange’],
[‘Black’,‘White’]]
Computer Science with Python–XII
print(L1[2][0][3])
(i) ‘c’ (ii) ‘a’
(iii) Black (iv) White
29. Identify the output of the following Python statements.
x=200
while x>10:
if x%2==0:
z=x//2
else:
z=x**2
print(z)
A.4 x=x-50
(i) 100 (ii) 100 (iii) 400 (iv) 100
75 50 200 22500
50 25 100 2500
25 10 50 625
30. Identify the output of the following Python statements.
for i in range(10):
if i==5:
continue
print(i,end=’’)
(i) 0123456789
(ii) 012346789
(iii) 123456789
(iv) 12346789
31. Write the output of the following Python statements:
L1 = [1,2,3,4,5]
L2=[4,5,6]
L1.extend(L2)
L1.insert(4,9)
L1[-5:-2]
(i) [1, 2, 3] (ii) [4, 5, 6, 9]
(iii) [9, 5, 4, 5] (iv) [9, 5, 4]
32. What will be the output of the following code?
import pickle
list1 = ['Red','Green','Orange','Yellow','Brown']
fobj = open("file.dat",'wb')
l=pickle.dump(list1,fobj)
fobj.close()
fobj = open("file.dat",'rb')
l=pickle.load(fobj)
for i in range(len(l)-1,0,-1):
print(l[i])
fobj.close()
(i) Red (ii) Brown (iii) Yellow (iv) Brown
Green Yellow Orange Yellow
Orange Orange Green Orange
Yellow Green Red Green
Brown Red
33. Suppose the content of ‘Student.dat’ file is:
print(number1)
funct1(2)
print(number1)
A.6
(i) 200 (ii) 100 (iii) 100 (iv) 200
40000 10000 40000 10000
38. What will be the output of the following code?
import random
color = ['Red', 'Orange', 'Yellow', 'Black', 'Cyan']
for c in range(len(color)):
p = random.randint(2,4)
print(color[p],end='$')
(i) Red$Red$Cyan$Orange$Yellow$
(ii) Cyan$Black$Black$Cyan$Yellow$
(iii) Black$Red$Black$Red$Black$
(iv) Black$Orange$Yellow$Black$Black$
39. What is the output of the following code snippet?
def flipnumber(L,y):
for i in range(y):
if L[i]%3==0:
L[i]**=3
if L[i]%2==0:
L[i]**=2
L=[3,2,4,8,9]
flipnumber(L,5)
for i in L:
print(i,end='#')
(i) 9#2#8#16#81#
(ii) 27#4#16#64#729#
(iii) 9#8#16#64#729#
(iv) 27#8#16#81#729#
40. Consider a file ‘quote.txt’
If you’ll look at what you have in life,
you’ll always have more.
If you look at what you don’t have in life,
You’ll never have enough.
but
44. What will be the output of the following code?
def Sum():
global p
p=p+7**2
print(p, end= '#')
p = 10
print(p,end= '@')
Sum()
print(p)
(i) 10@59#59 (ii) 59@10#59
A.8 (iii) 59@59#10 (iv) 10@10#10
45. What will be the output of the following code if the contents of the file ‘File1.txt’ are:
String may refer to
fileobj = open(“File.txt”,’w’)
fileobj.write(“Letters\n”)
fileobj.write(“Numbers\n”)
fileobj.write(“Special characters”)
fileobj.close()
fileobj = open(“File.txt”,’r’)
print(fileobj.read()
fileobj.close()
(i) Special Characters
(ii) letters
(iii) String may refer to
Letters
Numbers
Special Characters
(iv) Letters
Numbers
Special Characters
46. Consider the content of ‘rhyme.txt’ file is:
ead, shoulders, knees and toes,
H
Knees and toes.
Head, shoulders, knees and toes,
Knees and toes.
And eyes, and ears, and mouth, and nose.
Head, shoulders, knees and toes,
Knees and toes.
What will be the output of the following code?
fileobj=open(‘rhyme.txt','r')
count = 0
l=fileobj.readlines()
for i in l:
if(i[0]=='H'):
count=count+1
print(count)
fileobj.close()
(i) 3 (ii) 6
(iii) 2 (iv) 1
47. Consider the following directory structure:
Admin
Sample Question Paper 1
A.9
There are three directories under root directory ‘Admin’. The current working directory is Final. Identify
the relative path name for file ‘Result1.xlsx’.
(i) .\Result1.xlsx (ii) Admin\Final\First Term\Result1.xlsx
(iii) ..\First Term\Result1.xlsx (iv) First Term\Result1.xlsx
48. The readlines() function returns:
(i) A list of integers (ii) String
(iii) A list of single characters (iv) A list of strings
49. What will be the output of the following code snippet?
Tup1=(9,3,5,[1,2,3],8)
Tup1[3][1]=10
print(Tup1)
(i) Error (ii) (9, 3, 5, [1, 10, 3], 8)
(iii) (9, 3, 5, [1, 10, 2, 3], 8) (iv) (3, 3, 3, [1, 10, 3], 10)
Section C
Case Study Based Questions
This section consists of 6 Questions (50 to 55). Attempt any 5 questions.
Rashi is learning Python in preparation for an internship exam. She is having a problem with one question
in which she has been assigned an incomplete Python code (given below) to create a CSV file called
‘Employee.csv.’ Assist her in completing the code that generates the CSV file with the given content.
Employee.csv
Empno,Name,Desig,Salary
E1,Bharti,Sales,30000
E2,Anuj,Marketing,50000
E3,Mudit,Accounts,64000
Incomplete Code:
______ #Statement 1
Csvfile = open(______, _______, newline=’’) #Statement 2
CsvObj = csv. ________( ________) #Statement 3
Rows = []
Fields = [‘Empnumber’, ‘EmpName’, ‘EmpDesig’, ‘EmpSalary’]
Rows.append(Fields)
for i in range(5):
Empno = input(“Enter Employee No:”)
Name = input(“Enter Employee Name:”)
Desig = input(“Enter Designation:”)
Salary = int(input(“Enter Salary:”))
records= [________________] #Statement 4
Rows.________(______) #Statement 5
_______._______(Rows) #Statement 6
Computer Science with Python–XII
Csvfile.close()
50. Identify the relevant module to import in the blank space in line marked as Statement 1.
(i) import pickle (ii) import txt
(iii) import csv file (iv) import csv
51. Identify the missing code for the blank space in line marked as Statement 2.
(i) “Employee.txt”, ‘rb’ (ii) “Employee.csv”, ’wb’
(iii) “Employee.csv”, ’w’ (iv) “Employee.dat”, ’w’
A.10
52. Choose the function name (with argument) that should be used in the blank space of line marked as
Statement 3.
(i) writer(“Employee.csv”) (ii) read(“Csvfile”)
(iii) writer(CsvObj) (iv) writer(Csvfile)
53. Identify the suitable code for blank space in line marked as Statement 4.
(i) Empno, Name, Desig, Salary (ii) “Empno, Name, Desig, Salary”
(iii) “Empno”, “Name”, “Desig”,”Salary” (iv) “Empno – Name- Desig – Salary”
54. Identify the suitable code for blank space in the line marked as Statement 5.
(i) insert(data) (ii) delete(data)
(iii) append(records) (iv) addrows(records)
55. Identify the suitable code for blank space in the line marked as Statement 6.
(i) Csvfile.load() (ii) CsvObj.dumprow()
(iii) Records.reader() (iv) CsvObj.writerows()
A.11
ANSWERS (SAMPLE QUESTION PAPER 1)
1. (ii) Keywords 2.
(i) A = (2,5,6,3,5,2,1,7) 3. (iii) print(Tup1[::2])
4. (iv) In ‘a+’ mode, both reading and writing operations can take place and new data is appended to the end of the existing
file.
5. (iii) File1.read(5) 6.
(ii) disp = fileobj.readlines() 7.
(iii) Both (ii) and (iii) 8. (iii) 12
print(disp[-1])
9. (iii) // 10.
(i) print(T1[3]) 11.
(iii) Binary file 12.
(iii) tell() 13.
(iii) dump()
14. (iii) It will place the pointer at 25 bytes from the beginning of the file.
15. (ii) You can pass positional argument in any order. 16. (iv) Both (ii) and (iv)
17. (iii) Calc_cube(5) 18. (iii) flush() 19.
(ii) Returns a writer object which writes data into CSV file.
20. (ii) , 21.
(i) reader(), writer() 22.
(i) Script mode
23. (iii) ’’’Program to calculate 24.
(iii) pickle.dump(colors, mybinfile)
Simple Interest ’’’
25. (iii) Dict1= (‘Marks1’: 80, ‘Marks2’: 90, ‘Marks3’: 96) 26. (iii) (240,) 27.
(iii) 3
28. (i) ‘c’ 29.
(i) 100 30.
(ii) 012346789 31.
(iv) [9, 5, 4]
75
50
25
32. (ii) Brown 33.
(iii) pass 34.
(iv) Error 35.
(ii) 153
Yellow
Orange
Green
36. (iii) 4000.0 45000.0 37. (iii) 100 38.
(ii) Cyan$Black$Black$Cyan$Yellow$
40000
39. (ii) 27#4#16#64#729# 40.
(i) 9
you’ll never
41. (i) hAPPY#HOUR1122#33 42.
(iv) No Output 43.
(iii) sometimes 44.
(i) 10@59#59
weaknesses
strengths
45. (iv) Letters 46. (i) 3 47.
(iii) ..\First Term\Result1.xlsx 48. (iv) A list of strings
Numbers
Special Characters
49. (ii) (9, 3, 5, [1, 10, 3], 8) 50.
(iv) import csv 51.
(iii) “Employee.csv”, ’w’
52. (iv) writer(Csvfile) 53.
(i) Empno, Name, Desig, Salary 54.
(iii) append(records)
55. (iv) CsvObj.writerows()
Computer Science with Python–XII
A.12