083 - CS - With - Python - Class 12 - Sample Paper 1 - Solved
083 - CS - With - Python - Class 12 - Sample Paper 1 - Solved
083 - CS - With - Python - Class 12 - Sample Paper 1 - Solved
Year: 2022-23
Class 12
Duration: 3 hours Max Marks: 70
General Instructions:
4. Section B has 07 Very Short Answer type questions carrying 02 marks each.
7. Section E has 02 questions carrying 04 marks each. One internal choice is given in Q35 against part c only.
ps
8. All programming questions are to be answered using Python Language only.
Ki
Ans True
Ans b) break
3. Which of the following options will not result in an error when performed on tuples in Python 1
where tupl=(5,2,7,0,3)?
a) tupl[1]=2
b) tupl.append(2)
c) tupl1=tupl+tupl
d) tupl.sort()
ANs c) tupl1=tupl+tupl
4.
Ans
a) Error
b) False
c) 0
d) -1
d)-1
ps
What is the value returned by find() function for an unsuccessful search of sequence in the given
string?
1
5. Choose the appropriate statement to change the "year" value from 2000 to 2015. 1
Ki
car = {
"brand": "Maruti Suzuki",
"model": "Dzire",
"year": 2000
}
a) car["year"] = 2015
b) car.year = 2015
c) car.year[2015]
d) year = 2015
Ans b) tell()
8. By using an aggregate function, the __________clause filters the results of the GROUP BY 1
clause.
a) HAVING
b) ORDER BY
c) DISTINCT
d) GROUP BY
Ans a) HAVING
9. What is the meaning of “ORDER BY” clause in MySQL? 1
a) Sorting your result set using column data
b) Aggregation of fields
c) Sorting your result set using row data
d) None of the above
Ans
10.
ps
a) Sorting your result set using column data
What will happen when you run the following MySQL statement?
a) Error
b) No Error
Ki
Ans b) No Error
11. To read two characters from a file object infile, we use ____________. 1
a) infile.read(2)
b) infile.read(0,3)
c) infile.readline(2)
d) infile.readlines()
Ans a) infile.read(2)
Ans a) FROM
13. In an environment with many high-voltage devices, the best transmission medium would be 1
_______.
14. Observe the given SQL query and choose the correct option. 1
15.
ANs
16.
b) False
a) True
ps
State True or False:
a) True
a) Mysql-connector
Ki
b) Connector-Python
c) Python-connector
d) Mysql-Python-connector
ANs a) Mysql-connector
Q17 and 18 are Assertion and Reasoning based questions. Mark the correct choice as
a) Both A and R are true and R is the correct explanation for A.
b) Both A and R are true , but R is not the correct explanation for A.
c) A is True but R is False.
d) A is false but R is True.
17. Assertion (A): The scope refers to different parts of the function and program within which a 1
variable or value is legal and accessible.
Reason (R): Global is a keyword to create global variable.
Ans b) Both A and R are true , but R is not the correct explanation for A.
18. Assertion (A): The pickling module consist of two main functions. load() is used during the 1
pickling process, whereas dump() is used during unpickling process.
Part- B
19. Sejal has written a code to print prime numbers between given range. Her code is having errors. 2
Rewrite the correct code and underline the corrections made.
def prime(lower,up)
Print("Prime numbers between", lower, "and", upper, are:)
for num in range(lower, upper + 1):
if num > 1:
for i in range(2, num)
if (num % i) = 0:
break:
else:
print(num)
def prime(10,20)
ps
print("Prime numbers between", lower, "and", upper, "are:")
for num in range(lower, upper + 1):
if num > 1:
for i in range(2, num):
if (num % i) == 0:
else:
prime(10,20)
break
print(num)
20. Your friend wishes to install a wireless network in his office. Explain to him the difference 2
Ki
between guided and unguided media.
OR
ANs
Basis for
Guided Media Unguided Media
Comparison
OR
A computer network consists of two or more computers that are linked to share resources
such as printers and CD-ROMs, exchange files, or allow electronic communications.
Advantages of a network:
• A user can logon to a computer anywhere on the network and access their work files
from the file server.
• A network provides the means to exchange data among the computers.
• Computers can be managed centrally- with the same software installed on each one.
• Time- It is much faster to install an application once on a –network and copy it across the
network to every workstation.
• Networking also provides the function of back-up.
21.
ps
• Networking provides a flexible networking environment.
• Security - The Network Manager can allocate usernames and passwords to all the users
to help prevent unauthorised access.
Fill the blanks in the following code:
import ________#statement 1
with open("Text.csv", 'r') as ________#statement 2
L = csv.reader(fin)
for line in ___: #statement 3
print(___________) #statement 4
2
Ki
Choose the correct option to fill in statement 1,2,3,4, respectively.
a) csv, fin, L, line
b) CSV , f , fin , line
c) CSV , fin , l , line
d) None of these
22. What is the difference between the primary key and unique key? 2
Ans Both primary and unique key carry unique values, but the primary key cannot have a null value,
whereas the Unique key can. In a table, there cannot be more than one primary key, but unique
keys can be multiple.
OR
def Display(str):
m=""
for i in range(0,len(str)):
if(str[i].isupper()):
m=m+str[i].lower()
elif str[i].islower():
else:
print(m)
ps
m=m+str[i].upper()
if i%2==0:
m=m+str[i-1]
else:
m=m+"#"
Display('Fun@Python3.0')
25. Differentiate between fetchone() and fetchall() methods with suitable examples for each. 2
OR
Differentiate between degree and cardinality.
Ans fetchall() fetches all the rows of a query result. An empty list is returned if there is no record to
fetch the cursor.
fetchone() method returns one row or a single record at a time. It will return None if no more
rows / records are available.
OR
Degree is the total number of attributes in the table, whereas, cardinality is the total number of
tuples in the table.
Part- C
26. 1+1+
a) 1
SELECT *
FROM foods
NATURAL JOIN company;
b)
Twinkle is using a table EMPLOYEE. It has the following columns:
ps
Code, Name, Salary, Dept code. She wants to display maximum salary Department wise.
She wrote the following command:
b)
c)
DDL stands for Data definition language. It is the subset of a database that defines the data
structure of the database when the database is created. For example, we can use the DDL
27. Write a function in Python to count and display the total number of words in a text file. 3
OR/
Write a function display_words() in Python to read lines from a text file "poem.txt", and display
those words, which are less than 4 characters.
OR
ps
def display_words():
file = open("poem.txt","r")
data = file.read()
words = data.split()
for word in words:
if len(word) < 4:
print(word, end=" ")
file.close()
display_words()
Ki
28. a) Write SQL queries for (i) to (iv), which are based on the following tables. 3
TABLE : ACCOUNT
TABLE : TRANSACT
i. To display the details of all the transactions of TYPE Deposit from Table TRANSACT.
Ans
a)
1. SELECT * FROM TRANSACT WHERE TYPE = 'Deposit ';
2. SELECT ANO,AMOUNT FROM TRANSACT
WHERE DOT >= '2017-10-01' AND DOT <= '2017-10-31' ;
OR
SELECT ANO,AMOUNT FROM TRANSACT WHERE DOT BETWEEN '2017-10-01' AND '2017-
10-31' ;
3. SELECT MAX(DOT) FROM TRANSACT WHERE ANO = 103;
4. SELECT ACCOUNT.ANO,ANAME,DOT FROM ACCOUNT,TRANSACT
WHERE ACCOUNT.ANO=TRANSACT.ANO AND AMOUNT <=3000;
b)
ps OR
SELECT A.ANO,ANAME,DOT FROM ACCOUNT A,TRANSACT T
WHERE A.ANO=T.ANO AND AMOUNT <=3000;
DELETE command is used to remove information from a particular row or rows. If used without
condition, it will delete all the row information, but not the structure of the table. It is a DML
command.
DROP table command is used to remove the entire structure of the table and information. It is a
DDL command.
Ki
29. Write a Python program using the function to accept characters in a list, then find and display 3
vowels present in the list.
if(alphabet in vowels):
return True
else:
return False
OR
Ans host=[ ]
ch='y'
def push(host):
hn=int(input("Enter hostel number"))
ts=int(input("Enter Total students"))
tr=int(input("Enter total rooms"))
temp=[hn,ts,tr]
host.append(temp)
def pop(host):
ps
if(host==[]):
print("No Record")
else:
print("Deleted Record is :",host.pop())
def display(host):
l=len(host)
print("Hostel Number\tTotal Students\tTotal Rooms")
for i in range(l-1,-1,-1):
print(host[i][0],"\t\t",host[i][1],"\t\t",host[i][2])
Ki
while(ch=='y' or ch=='Y'):
print("1. Add Record\n")
print("2. Delete Record\n")
print("3. Display Record\n")
print("4. Exit")
op=int(input("Enter the Choice"))
if(op==1):
push(host)
elif(op==2):
pop(host)
elif(op==3):
display(host)
elif(op==4):
break
ch=input("Do you want to enter more(Y/N)")
OR
MyStack=[]
def Push(rollno):
MyStack.append(rollno)
Part- D
31. Western School in Mumbai is starting up the network between its different wings. There are four
buildings, named as SENIOR, JUNIOR, ADMIN, and HOSTEL as shown below:
ps
Number of Computers in Each Building:
Ki
a) Suggest the cable layout of connections between the buildings. 1
b) Suggest the most suitable place (i.e., building) to house the server of this school and 1
provide a suitable reason.
c) Suggest the placement of the following devices with justification: 1
• Repeater
• Hub/Switch
d) The organisation also has an inquiry office in another city about 50-60 km away in a hilly 1
region. Suggest the suitable transmission media to interconnect to school and inquiry
office out of the following:
• Fibre optic cable
• Microwave
• Radio waves
e) Suggest a protocol that shall be needed to provide video conferencing solution between
various buildings.
b) Server can be placed in the ADMIN building as it has the maximum number of computers.
c) Repeater can be placed between ADMIN and SENIOR building as the distance is more than
110 m. Hub can be placed in each block.
d) Radio waves can be used in hilly regions as they can travel through obstacles.
e) Protocol: VoIP
32. a) Find the output of the following: 2+3
n=5
r = b**p
return r
ps
def calcSquare(a):
a = power(a, 2)
return a
def power (b , p):
result = calcSquare(n)
print(result)
Ki
b) Write the steps to perform an Insert query in database connectivity application.
Table ‘student’ values are rollno, name, age (10,’Raman’,26).
RollNo – integer
Name – string
Age – integer
OR
a) Predict the output of the code given below:
s="PyThontest2"
n = len(s)
m=""
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):
m = m +s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'):
m = m +s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m +'&'
print(m)
Name – string
Age – integer
ps
b) Write the steps to perform an Insert query in database connectivity application.
Table ‘student’ values are rollno, name, age (10,’Raman’,26)
RollNo – integer
Write the following missing statements to fetch all records of a table Student at run time:
Statement 1 – to form the cursor object
Statement 2 – to execute the command that fetch all records of a table Student .
Statement 3- to fetch all records
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="
123" ,database="school")
mycursor=_________________________# Statement 1
mycursor._____________________ # Statement 2
myrecords=___________________ # Statement 3
for x in myrecords:
print (x)
Ans a)25
b)
import mysql.connector as mydb
OR
a) pPtHhonEes&
b)
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="
123" ,database="school")
mycursor=mydb.cursor()
mycursor.execute("select * from student")
myrecords=mycursor.fetchall()
for x in myrecords:
print (x)
33.
ps
Write a program to search the record from “data.csv” according to the admission number input
from the user. The structure of record saved in “data.csv” is Adm_no, Name, Class, Section, and
Marks. Also, write a function ADD() to accept and add data of an employee to a CSV file
‘data.csv’. Each record consists of a list with field elements as Adm_no, Name, Class, Section, and
Marks, respectively.
OR
a) Give any one point of difference between a binary file and a csv file.
5
b) Write a program to show the details of the student who scored the highest marks. Data
Ki
stored in “Details.csv” is given below:
1, Amit, 87
2, Aman, 98
3, Pooja, 85
4, Sandhya, 80
for row in d:
if int(row[0])==adm:
break
else:
import csv
def ADD():
fout=open("data.csv","a",newline="\n")
wr=csv.writer(fout)
adm_no=int(input("Enter Adm number :: "))
name=input("Enter name :: ")
cls=int(input("Enter Class :: "))
sec=input("Enter Section :: ")
mrk=int(input("Enter Marks :: "))
lst=[adm_no,name,cls,sec,mrk]
wr.writerow(lst)
OR
a)
ps
fout.close()
b)
import csv
f=open("details.csv","r")
d=csv.reader(f)
next(f)
max=0
for i in d:
if int(i[2])>max:
max=int(i[2])
f.close()
f=open("data.csv","r")
d=csv.reader(f)
next(f)
for i in d:
if int(i[2])==max:
print(i)
f.close()
3 1. Write SQL queries for (i) to (iv), which are based on the tables Account and Transact. 4
4
.
TABLE : ACCOUNT
34.
TABLE : TRANSACT
ii)
iii)
iv)
ps
i) To display the details of all transactions of TYPE Deposit from Table TRANSACT.
To display the ANO and AMOUNT of all Deposits and Withdrawals done in the month
of October 2017 from table TRANSACT.
To display the last date of transaction (DOT) from the table TRANSACT for the
Accounts having ANO as 103.
To display all ANO, ANAME, and DOT of those persons from tables ACCOUNT and
TRANSACT who have done transactions less than or equal to 3000.
Ki
Ans i) SELECT * FROM TRANSACT WHERE TYPE = 'Deposit ';
import _________________#statement 1
with open ("file.dat", "wb") as ____________#Statement 2:
while True: