0% found this document useful (0 votes)
71 views

Class 12 Term - 01 Key

Uploaded by

s88527184
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Class 12 Term - 01 Key

Uploaded by

s88527184
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

MARUTHI SENIOR SECONDARY SCHOOL

Affiliated to CBSE, Aff. No. 2930027


Maruthi Nagar, Karuvadikuppam, Lawspet, Puducherry – 605 008.
TERM – 1
COMPUTER SCIENCE
Class: XII Marks: 70
Date & Day: Duration: 3.00 Hours.

Q.No. Answer the following Questions: (All Questions are Compulsory) Marks
1. which of the following statement is not true for parameter passing to function? (1)
(a) you can pass positional arguments in any order.
(b) you can pass keyword argument in any order.
(c) you can call a function with positional any keyword arguments.
(d) positional arguments must be before keyword arguments in a function.
Ans: (a) you can pass positional arguments in any order.
2. A ______________ argument can be skipped in the function call statement. (1)
Ans: Default arguments.
3. Given a Tuple tup1= (10, 20, 30, 40, 50, 60, 70, 80, 90). (1)
What will be the output of print (tup1 [3:7:2])?
(a) (40,50,60,70,80) (b) (40,50,60,70) (c) [40,60] (d) (40,60)
Ans: (d) (40,60)
4. Which of the following is/are character set? (1)
(a) Alphabets (b) Digits (c) White space (d) all of these
Ans: (d) all of these
5. def Interest(p,c,t=2,r=0.09): (1)
return p*t*r
Considering the above defined function which of following function call are legal.
1. Interest(p=1000,c=5)
2. Interest(r=0.05,5000,3)
3. Interest(500,t=2,r=0.05)
4. Interest(c=4,r=0.12,p=5000)
(a) 1 , 2 and 4 (b) 2 & 3 (c) 1 &4 (d) 3 & 4
Answer: (c) 1 &4
6. Find the valid identifier from the following and state the reason. (1)
none, address, Name, pass.

Ans: none, address, Name are valid identifiers because pass is a keyword.
7. Assertion: pickling is the process whereby a python object hierarchy is converted (1)
into a byte-stream.
Reason: pickling process is used to work with binary files as a binary file works with
byte-stream.
(a) both A and R are true but R is not the correct explanation of A.
(b) both A and R are true and R is the correct explanation of A.
(c) A is true but R is false.
(d) R is true but A is false.
Ans: (a) both A and R are true but R is not the correct explanation of A.
8. The relative paths are relative to the current working dictionary? (True/false) (1)
Ans: True
9. In a stack, which item is accessed first. (1)
(a) The item above the first item.
(b) The item added least recently.
(c) The item added most recently.
(d) The item below the last item.
Ans: (c) The item added most recently.
10. Write Python code to open a file named "example.txt" in write mode and write the (1)
string "Hello, World!" to it with a file object called file.
Ans: With open ("example.txt", "w") as file:
file.write ("Hello, World!")
11. The peek operation refers to accessing/inspecting the top element in the stack. (1)
(True / False)
Ans: True.
12. Stack overflow condition is raised in ____________ operation whereas Stack (1)
underflow condition is raised in _____________ operations.
Ans: Push, Pop
13. To create a connection between MYSQL database and Python application connect() (1)
function is used. Which of the following are mandatory arguments required to
connect any database from Python.
(a) Username, Password, Hostname, Database Name, Port
(b) Username, Password, Hostname
(c) Username, Password, Hostname, Database Name
(d) Username, Password, Hostname, Port
Ans: (c)
14. Assertion (A): CSV file is a human readable text file where each line has a number (1)
of fields, separated by commas or some other delimiter. Reason
Reason (R): writerow() function can be used for writing into writer object.
(a) Both A and R are true and R is the correct explanation for A
(b) Both A and R are true and R is not the correct explanation for A
(c) A is True but R is False
(d) A is false but R is True
Ans: (b)
15. What is the output of following code: (1)
T=(100)
print(T*2)
(a) Syntax error (b) (200,) (c) 200 (d) (100,100)
Ans: (c) 200
16. Identify the output of the following Python statements. (1)
x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]]
y = x[1][2]
print(y)
(a) 12.0 (b) 13.0 (c) 14.0 (d) 15.0
Ans: (d) 15.0
17. Syntax of seek function in Python is myfile.seek(offset, reference_point) where (1)
myfile is the file object. What is the default value of reference_point?
(a) 0 (b)1 (c) 2 (d) 3
Ans: (a) 0
18. What will be the output of the following code? (1)
x=3
def myfunc():
global x
x+=2
print(x, end=' ')
print(x, end=' ')
myfunc()
print(x, end=' ')
(a) 3 3 3 (b) 3 4 5 (c) 3 3 5 (d) 3 5 5
Ans: (d) 3 5 5
19. What is the output of the following code snippet? (1)
def ChangeVal(M,N):
for i in range(N):
if M[i]%5 == 0:
M[i]//=5
if M[i]%3 == 0:
M[i]//=3
L = [58,77,75,19]
ChangeVal(L,4)
for i in L:
print(i,end="#")
(a) 58#77#15#19# (b) 58#70#15#19#
(c) 58#77#5#19# (d) 58#77#5#18#
Ans: (c) 58#77#5#19#
20. In ________ files each line terminates with EOL or ‘\n’ or carriage return, or ‘\r\n’. (1)
(a) Binary file (b) CSV file (c) Text file (d) Both (a) and (d)
Ans: (c) Text file
21. Expand: LIFO & FIFO (1)
Ans: Last In First Out & First In First Out
22. The writer() has how many mandatory parameters? (1)
Ans: 1
23. Nabithra is trying to read a list l1 from a binary file ‘num’. Consider the following (1)
code written by her.
import pickle
f1 = open("num",'rb')
l1=__________________#Statement 1
print(l1)
f1.close()
Identify the missing code in Statement 1.
(a) pickle.load(f1) (b) pickle.load(l1,f1)
(c) pickle.read(f1) (d) pickle.dump(l1,f1)

Ans: (a) pickle.load(f1)


24. Consider the following expression: not True and False or not False (1)
Which of the following will be the output:
(a) True (b) False (c) None (d) NULL
Ans: (a) True
25. What is a delimited text file? (1)
Ans: A delimited file is a sequential file with column delimiters. Each delimited
file is a stream of records, which consists of fields that are ordered by column.
26. Write a function, lenWords (STRING), that takes a string as an argument and returns (2)
a tuple containing length of each word of a string. For example,
if the string is "Come let us have some fun" the tuple will have (4, 3, 2, 4, 4, 3)
Ans: def lenWords (STRING) :
T=()
L=STRING.split( )
for word in L:
length = len(word)
T=T +(length,)
return T
27. Enlist a few of the fields where you feel a stack is used in real life. (2)
Ans:
1. Browsers History
2. Mobile Phone Call log
3. Tubewell boring machine
4. Undo and redo commands in software
4. Bangles on woman’s wrist
28. Write a function to inspect an element from the stack. (2)
Ans:
def peek(stk):
if stk==[]:
return "UnderFlow"
else:
top = len(stk)-1
return stk[top]
29. Write a function cust_data() to ask user to enter their names and age to store data in (2)
customer.txt file.
Ans:
def cust_data():
name = input("Enter customer name:")
age=int(input("Enter customer age:"))
data = str([name,age])
f = open("customer.txt","w")
f.write(data)
f.close()
30. Write Functions in python for PushS(List) and for PopS(List) for performing PUSH (2)
and POP operations with a Stack of List containing Integers.
Ans:
Def PushS(List):
N = int(input(“Enter Integer: ”))
List.append(N)
def PopS(List):
if(List == []):
print(“Stack empty; UNDERFLOW!!”)
else:
print(“Deleted value:”. List.pop())
31. which function is used to execute the query? What does it return? (2)
Ans: Execute() function with cursor object<can be used to execute sql query. It
returns the resultset.
• Syntax: cursorObject. execute(‘’mysql query string”)
• Example: cursorObj.execute(‘’SELECT*FROM STUDENT’’)
32. Differentiate between fetchone() and fetchmany(). (2)
Ans:
(i) fetchone() ->This method retrieves the next row of a query resultset and
returns a single sequence or None if no more rows are available.
By default it returns tuple.
(ii) fetchmany() -> This method fetches the next set of rows of a query resultset
and returns a list of tuples.
If no more rows are available it returns an empty list.
33. The code given below accepts a number as an argument and returns the reverse (2)
number. Observe the following code carefully and rewrite it after removing all
syntax and logical errors. Underline all the corrections made.
define revNumber (num) :
rev=0
rem=0
While n > 0 :
rem == num %10
rev = rev *10 + rem
n = num //10
return r
print (revNumber (1234) )
Corrected Code:
def revNumber (num) :
rev=0
rem=0
while num > 0 :
rem =num %10
rev = rev *10 + rem
num = num //10
return rev
print (revNumber (1234) )
34. A file sports.dat contains information in the following format: (3)
[Event, Participant] for each participant. Write a function that would read contents
from sports.dat and creates a file called athletics.dat copying only those records from
sports.dat where the event name is “Athletics”.
Ans:
def copy_athletics( ) :
f = open("sports.dat","rb")
fa = open ("athletics.dat","wb")
rec = [ ]
try:
det = pickle.load(f)
for í in det:
if i[0] =="Athletics":
rec.append(i)
pickle.dump(rec,fa)
except EOFError:
f.close ( )
fa.close ( )
35. Write a Python database connectivity script that deletes records from category table (3)
of database items that have a name = ‘Stockable’.
Ans:
import mysql.connector as ctor
dbcon = ctor.connect(host = “localhost”, user = “learner”, passwd = “fast”,
database = ‘items’)
cursor = dbcon.cursor()
sql1 = “DELETE FROM category WHERE name = ‘%S’ ”
data1 = (‘Stockable’ , )
cursor.execute(sql1, data1)
dbcon.commit()
print(“Rows Affevted: ”, cursor.rowcount)
dbcon.close()
36. Write a function in python to read a text file, Alpha.text and display those lines (3)
which begin with the word 'You'.
Ans:
def test ( ) :
fObj1 = open ("Alpha.txt","r")
data = fObj1.readlines( )
for line in data:
L=line.split( )
if L[0] =="You":
print (line)
fObj1.close( )
37. Give step by step process of postfix form the following expression: (3)
A*(B + (C +D) * (E + F) / G) * H
Ans: A B C D + E F + * G / + *H*
38. What is a stack data structure, and what are its fundamental operations? (3)
Ans: A stack is a linear data structure that follows the Last-In, First-Out
(LIFO) principle. It has two primary operations: "push" to add an element to
the top of the stack and "pop" to remove the top element. Additionally, it
typically supports "peek" to view the top element without removing it and
"isEmpty" to check if the stack is empty. Stacks are commonly used for
managing function calls, undo functionality, and other scenarios where the
order of data retrieval is crucial.
39. (a) Praveena of class 12 is writing a program to create a CSV file “clients.csv”. She (4 + 1)
has written the following code to read the content of file clients.csv and display the
clients’ record whose name begins with “A‟ and also count as well as show no. of
clients with the first letter “A‟ out of total records. As a programmer, help her to
successfully execute the given task.
Consider the following CSV file (clients.csv):

1 Aditya 2021
2 Arjun 2018
3 Aryan 2016
4 Sagar 2022
Read the questions given below and fill in the gaps accordingly: (1 + 1 + 2)
1.State the module name required to be written in Line-1.
2.Mention the name of the mode in which she should open a file.
3.Fill in the gaps for given statements – Line-2 and Line-3.
Ans:
1. csv
2. r mode
3. Line 2 – “client.csv”,”r” and Line 3 – reader
(b) The explicit conversion of an operand to a specific type is called ______.
Ans: Type casting.
40. (a) Write a function PUSH(L) and POP(Stk), where L is List of integers and Stk is a (3+1)
stack. In PUSH function create two stack StkO and StkE, then read the list L and
push all the even element in StkE and push all the odd element in StkO. At last
return both the stacks. In POP function pop the number from the stack and
display.

Ans:
def PUSH(L):
StkO = []
StkE = []
for i in L:
if i%2 == 0:
StkE.append(i)
else:
StkO.append(i)
return StkO, StkE
def POP(Stk):
if len(Stk) == 0
print(“Stack is Empty”)
else:
while len(Stk) != 0:
print(Stk.pop())

(b) How Peek in Stack described to use as Python code?


Ans: We can use <stack>[top], where <stack> is a list and [top] is an integer
having value equal to len(<stack>) -1, ie., top = len(stk) – 1.
41. Consider the following code and answer the questions that follow: (4+1)
Book={1:'Thriller', 2:'Mystery', 3:'Crime', 4:'Children Stories'}
Library ={'5':'Madras Diaries','6':'Malgudi Days'}
(1) Ramesh needs to change the title in the dictionary book from ‘Crime’ to ‘Crime
Thriller’. He has written the following command:
>>> Book[‘Crime’] = ’Crime Thriller’
But he is not getting the answer. Help him choose the correct command:
a. Book[2]=’Crime Thriller’
b. Book[3]=’Crime Thriller’
c. Book[2]=(’Crime Thriller’)
d. Book[3] =(‘Crime Thriller’)
Answer: b. Book[3]=’Crime Thriller’

(2) The command to merge the dictionary Book with Library the command would
be:
a. d=Book+Library
b. print(Book+Library)
c. Book.update(Library)
d. Library.update(Book)
Answer: d. Library.update(Book)

(3) What will be the output of the following line of code:


>>> print(list(Library))
a. [‘5’,’Madras Diaries’,’6’,’Malgudi Days’]
b. (‘5’,’Madras Diaries’,’6’,’Malgudi Days’)
c. [’Madras Diaries’,’Malgudi Days’]
d. [‘5’,’6’]
Answer: d. [‘5’,’6’]

(4) In order to check whether the key 2 is present in the dictionary Book, Ramesh
uses the following command:
>>> 2 in Book
He gets the answer ‘True’. Now to check whether the name ‘Madras Diaries’ exists
in the dictionary Library, he uses the following command:
>>> ‘Madras Diaries’ in Library
But he gets the answer as ‘False’. Select the correct reason for this:
a. We cannot use the in function with values. It can be used with keys only.
b. We must use the function Library.values() along with the in operator
c. We can use the Library.items() function instead of the in operator
d. Both b and c above are correct.
Answer: b. We must use the function Library.values() along with the in operator

(5) What are in and not in membership operators in dictionary? Write its syntax.

Ans: These operators check whether a specific key is present in dictionaries or


not. If present the result will be True else False.
Syntax: key in Dict_name and key not in Dict_name.

*****************

You might also like