0% found this document useful (0 votes)
7 views4 pages

Revision Test Series - 3: Computer Science

Uploaded by

rilixip218
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)
7 views4 pages

Revision Test Series - 3: Computer Science

Uploaded by

rilixip218
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/ 4

REVISION TEST SERIES – 3

CS- 3 COMPUTER SCIENCE


Time : 1½ hrs SET A Marks : 35

SECTION A-MULTIPLE CHOICE QUESTIONS


1 Syntax for opening Student.csv file in write mode is 1
myfile = open("Student.csv","w",newline='').
What is the importance of newline=''?
a) A newline gets added to the file
b) Empty string gets appended to the first line.
c) Empty string gets appended to all lines.
d) EOL translation is suppressed
2 Which of the following is a function of csv module? 1
a)reader() b)read() c)readlines() d)read(n)
3 Which of the following operations returns the top item of the stack
without removing it? (1)
a)push b)pop c)peek d)input
4 Trying to remove items from an empty stack is termed _____ 1
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 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
5 Assertion: The push operation in a stack adds an item to the top of the 1
stack
Reasoning: The pop operation in a stack removes an item from the
bottom of the stack
6 Expand a) csv b)LIFO 1
7 Assertion: If the size of a stack is 5 and a sixth element is inserted, 1
then Underflow happens
Reason: Overflow is a condition which occurs in bounded stack
A. Both Assertion and reason are true and reason is correct
explanation of assertion
B. Assertion and reason both are true but reason is not the correct
explanation of assertion
C. AssertiON is true, reason is false.
D. Assertion is false, reason is true
8. State true or False 1
For loop can be used for traversing a stack

1
SECTION B- VERY SHORT ANSWER QUESTIONS
9 Write a python statements for the following 2
a) Define stack student as a list of 5 student names
b) To remove the last element from a stack student using suitable
method/function.
10 Convert the following infix expression into its equivalent postfix 2
expression using stack and show the contents of stack after execution
of each operation
( ( A – B ) * ( D / E ) )/ ( F * G * H )
OR
Evaluate the following postfix notation of expression: (Show status of
stack after each operation.
True, False, NOT, OR, False, True, OR, AND
11 Give any two characteristics of stacks. 2
12 KV is making the data base of students for that data is stored in list 2
stack
form but the code is not complete , complete the code as per
your
knowledge and make the software run:

std=[ ]
def push(std):
n=int(input(“name of student”)
r=int(input(“rollnoof student”)
c=int(input(“class”))
__________________ #statement 1
std.append(temp)
def pop(std):
______________ # statement 2
print(“No Record”)
else:
print(“Deleted Record is “, std.pop())

(i) Write code for statement 1


(ii)Write code for statement 2
SECTION C-SHORT ANSWER QUESTIONS
13 Rohan has created a dictionary containing Team name and score as 3
key value pairs of 7 Cricket Teams. Write a program, with separate
user define functions to perform the following operations
● Push the keys (name of the team ) of the dictionary into a stack,
where the
corresponding value (score) is greater than 100.
● Pop and display the content of the stack.

2
For example:
If the sample content of the dictionary is as follows:
T={“Chennai Super “:76, “Mumbai Indians”:87, “Royal
Challengers”:89,
“Kolkatta Knight Riders”:65, “Rajasthan Royals”:110,
“MasterBlasters”:106,
“Punjab Kings”:95 }
The output from the program should be:
Rajasthan Royals MasterBlasters
14 Write a function LShift(Arr,n) in Python, which accepts a list Arr of 3
numbers and n is no. of elements in Arr where all elements are shifted
to left and the first element will be placed atthe end of the list (3)
Sample Input Data of the list
Arr= [ 10,20,30,40,12,11]
Output
Arr = [20,30,40,12,11,10]
15 Create a csv file called ‘Groceries’ to store information of different 3
items existing in a shop. The information is to be stored with respect to
each item code, name, price, quantity. Write a function to accept the
data from user and store it permanently in csv file.
OR
Write a Python program that reads data from a CSV file named
"data.csv" using the csv.reader() object. For each row, if the value in
the second column (index 1) is greater than 50, write that row into a
new CSV file named "high_scores.csv" using the csv.writer() object.
SECTION D-LONG ANSWER QUESTIONS
16 A csv file "Happiness.csv" contains the data of a survey. Each record 5
of the file contains the following data: (4)
● Name of a country
● Population of the country
● Sample Size (Number of persons who participated in the
survey in that country)
● Happy (Number of persons who accepted that they were
Happy)

For example, a sample record of the file may be: [‘Signiland’,


5673000, 5000, 3426]
Write the following Python functions to perform the specified
operations on this file:
(I) Read all the data from the file in the form of a list and
display all those records for which the population is more
than 5000000.
(II) Count the number of records in the file

3
OR
Alam has a list containing 10 integers. You need to help him create a
program with separate user defined functions to perform the following
operations based on this list.(4)
● Traverse the content of the list and push the even numbers
into a stack.
● Pop and display the content of the stack.
For Example:
If the sample Content of the list is as follows: N=[12, 13,
34, 56, 21, 79, 98, 22, 35, 38] Sample Output of the code
should be: 38 22 98 56 34 12
SECTION E-CASE BASED QUESTIONS
17 Shantanu of class 12 is writing a program to create a CSV file (5) 5
“BoardDetails.csv” which will contain Board RollNo, StuName,
DateOfBirth for some entries. He haswritten the following code.
As a programmer, help him to successfully execute thegiven task.

import _____________ #Line 1


defaddCsvFile(BoardRollNo,StuName, DateOfBirth):
f=open('________________,'a',newline='') #Line 2
x = csv.writer(f)
x.writerow([BoardRollNo,StuName, DateOfBirth])
f.close()

defreadCsvFile():
f=open('BoardDetails.csv','__') #Line 3
y = csv._________ #Line 4
for row in y:
if (int(row[0])>9107750):
print(row[0],row[1])
f.close()

addCsvFile(9107752,"Sita Sharma","2003/10/21")
addCsvFile(9107751,"Gita Patel","2004/11/01")
addCsvFile(9107750,"Suresh Rao","2003/10/25")
readCsvFile()

a) Name the module he should import in Line 1.


b) Fill in the blank in Line 2 to open the file to write/add data
into the file.
c) Fill in the blank in line 3 to read from the csv file.
d) Fill in the blank in Line 4 to read data from the csv file
e) Write the output he will obtain while executing Line 5.

You might also like