0% found this document useful (0 votes)
22 views5 pages

ComputerScience 83782

Uploaded by

anirudh05.ramesh
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)
22 views5 pages

ComputerScience 83782

Uploaded by

anirudh05.ramesh
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/ 5

Sri Kumaran Children’s Home - CBSE

I Terminal Examination 2020 - 2021


Class: XII Subject: Computer Science Marks: 70
Date: 05.09.2020 Subject Code: 085 Time: 3 Hrs.

* Answer all Questions


* All programming questions to be answered in Python
* This question paper has 5 pages
* Question 1 has 10 questions (a-j)
* Question 2 has 10 questions (a – j)
* Question 3 has 4 questions (a-d)
Q.No Part Question Marks
1 (a) Identify the Python library that the following functions belong to: 1
i. randrange()
ii. match()
iii. request()
iv. variance()

(b) DisplayList() is in a module called ListM.py 1


i. Write a statement to import only this function from the ListM module and
call it DL.
ii. Write a statement to call the function if the entire Module has been
imported using *

(c) Consider the following two Lists 1


A=[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
B= [1, 2, 3, 5, 6, 7, 8 ,9, 10, 11, 12, 13]

Write a one line list comprehension which create a list that contains only the
elements that are unique between the lists.

Example list output would be C=[21,34,55,89,6,7,9,10,11,12]

(d) A function has the following function header: 1


def callme(x,y,z=3,w=5)

Which one of the following option/s are incorrect and why?


i. callme(x=1,y=4)
ii. callme(w=13,z=1,2)
iii. callme(x=1,z=4,w=11)
iv. callme(11,12,w=1)

(e) from math import * 1


a = 2.13
b = 3.7777
c = -3.12
print(int(a), floor(b), ceil(c), fabs(c))
a) 2 3 -4 3
b) 2 3 -3 3.12
c) 2 4 -3 3
d) 2 3 -4 3.12
(f) Name the file modes for the following requirement: 1
i. Text file to be opened for reading and writing, and gets truncated if it
already exists
ii. Binary file to be opened for reading and writing and data gets added at
the end if file exists
(g) Consider the following code: 1

original_list = [10, 22, 44, 23, 4]


new_list = list(original_list)
new2 = original_list
print(id(original_list))
print(id(new_list))
print(id(new2))

Will all the prints give the same result? Justify.


(h) How many times is the word ‘hello’ printed in the following statement? State 1
the different values of ch.
S="python rocks"
for ch in S[-4:-20:-2]:
print("hello")
(I) What will be the output of the following: 1
try:
print('try')
except:
print('Except')
else:
print(“Else”)
finally:
print('finally')
(j) What is the boundary condition for a queue when there is 1
a. One element left in a static queue
b. Empty Queue
c. Full Queue in case of a static Queue
2 (a) Rewrite the following Python code after removing any/all Syntactical Error(s) 2
with each correction underlined:
def que():
x= float(input("Enter a number")
if ceil(x)=x:
print("positive")
else:
x=*-1
print("made positive")
que()
(b) Find the errors and mark them: 2
def function1(l):
list = ['a', 'b', 'c', 'd', 'e']
L= list[10:1]
print(list[-6], L[0])
for i in list:
list = list.append(i+1)
print(list[i])
f1()
(c) Write the output of the following program: 2

i. b=[[9,6,1],[4,5,6],[7,7,0,2,12,45],[12,344,1]]
X=b[:3]
print(X)
X[0:1]=[2]
print(X[0:2][1:0:-1])

ii. numberGames = {}
numberGames[(1,2,4)] = 8
numberGames[(4,2,1)] = 10
numberGames[(1,2)] = 12
sum = 0
for k in numberGames:
sum += numberGames[k]
print(len(numberGames) + sum )
(d) Write the possible output/s of the following program: 2

import random
AR=[20,30,40,50,60,70]
FROM=random.randint(1,3)
TO=random.randint(2,4)
for K in range(FROM,TO+1):
print (AR[k],end="#")

(i) 30#40#60# (ii) 50# (iii) No Output (iv) 30#40

(e) Consider a file containing dictionaries. Each dictionary has rollno and marks as 2
keys. Based on the roll no the marks has to be changed.
Fill in the blanks.
import pickle
file1 = open("student.dat", "rb+")
search = int(input("Enter the roll no you want to change"))
while True :
try:
y=__________________
stud = _________________
if stud['roll'] == search:
marks = int(input("enter new marks"))
stud["marks"] = marks
___________________
___________________
break
except:
print("error")
break
file1.close()

(f) Write a program to read a file called me.txt and output the size of the file without 2
using the os module.
Evaluate the expression 20,45,+,20,10,-,15,+,* using stacks
(g) 2
(h) Give any two applications of a queue. 2
(i) Write a program to create a csv file Marks.csv and write the data Physics: 90 and 2
Chemistry: 100 into it
(j) Write the names of the functions (along with the module names if required)which 2
can do the following:
a. Function returns a string where lower case becomes upper case and vice
versa
b. Removes the last inserted key value pair from dictionary
c. Make iterables (can be zero or more), makes iterator that aggregates
elements based on the iterables passed, and returns an iterator of tuples.
d. Function used to open and read a URL.
3 (a) Using Stacks , display the conversion of the infix expression to postfix expression in 3
a tabular format:
(R-S)*(T/U)+V^W*N
(b) Write a program which uses the urllib module. The program should open the 3
website www.python.org, read the source code and count the number of times the
word python is mentioned in the source code. If a 404 occurs, the program should
print “Website not accessible”
(c) Write a function which receives a list of numbers and its length as parameter, The 3
function should have the following attributes:
a. Default parameters set to [] and 0
b. Should reverse each number in the list.
c. Should return 1 or 0 depending upon whether the list was changed or not
respectively
Example input : L[123,23,45], length =3
Return value: [321, 32,54]
(d) Write a python program to read a file called STORY.txt , for each line print the 3
number or words, vowels, consonants and special characters
e.g. if the file contains:
This is an example for story.txt
We will count the number of words
And the number of vowels
And the number of special characters

The program would display output as:


Line1: Words: 6, Vowels: 7, Consonants: 18, Special Char: 6
Line 2: Words: 7, Vowels: 9, Consonants: 18 , Special Char: 5

(e) Consider the following list of book names: 3


Who Tuesdays Memoirs Skipping Life of The The Da
moved with of a Christmas Pi Secret Vinci
my Morrie Geisha Code
Cheese?

Arrange them in descending lexicographical order using bubble sort.


Show each pass
(f) Consider a binary file which consists of dictionaries. Each dictionary contains the 3
name of a website and its category
{“Site”: “edchemy.org”, “cat”: “LMS”}
{“Site”: “amazon.com”,”cat”:”e-comm”}
{“Site”: “onlinesbi.com””cat”:”e-bank”}
And so on
Write a function to open an existing binary file called “Sites.dat” to update all sites
categories which have “e-comm” to “e-commerce”. Use the temporary file
concept.

(g) Consider a list of characters. Write a function which accepts the list of characters 3
and moves all the vowels to the beginning of the list.
Do not use any temporary array. No in built functions other than len () can be used.
All swaps must be in-place.
e.g. LIST WHICH HAS O, R, I, G, I, N, A, L becomes O, I, A, A, R , G, N, L
(h) Perform the following: (Write only the required python statement, all modules can 3
be considered inserted, default database is MySql)
a. Format a string to Insert a row into a table “Student” with column heading
“Id, Name, Class” with values taken from the user.
b. Supposing a results set rs contains rows from the above said table. How
would the code using fetchall () be different from fetchmany (). Show
programmatically. (Only the loop)
4. (a) Write a program containing two functions. For an existing list of numbers, write 4
two functions:
Function 1: accepts the list and deletes an element in the list in such a way that the
order of the elements does not change and the size of the list does not decrease

Function 2: accepts a sorted list , searches for the element and deletes it from the
list (List size can change)
*Search mechanism can be a simple call to the right function.

(b) Write a function which accepts a matrix as its parameter. The function should then 4
interchange the primary diagonal with its secondary diagonal.
e.g. Input : [4, 2, 3, 1,
5, 7, 6, 8,
9, 11, 10, 12,
16, 14, 15, 13]
Output : [1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
11, 14, 15, 16]
(c) A Stack STemp represents the temperatures of a city on different days. Write 4
functions which represent pop () and push () for the same. Implement the calls as
well.
(d) Consider the following MySQL table: 4
Table Name: Movies
Movie Id Movie Name Rating Price
M001 Last Chance 2 100
M002 Good Luck 3 200
M003 Experimental 4 500

Write a python program to connect to the database “Theatre” with user id and
password “user”.
a. With the help of the program Add a column to the table called Cast.
b. Set all values Of Cast to “Not Known”.
c. Retrieve data from the table where Movie starts with L.

*****BEST OF LUCK*****

You might also like