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

CBSE Class 12 Computer Science Sample Paper Set 2 for 2024-25 FREE PDF (1)

The document is a sample question paper for Class XII Computer Science, consisting of 37 compulsory questions divided into five sections with varying marks. It includes multiple-choice questions, programming tasks, and theoretical questions covering topics such as Python programming, SQL, and data structures. The total marks for the paper are 70, and the time allowed for completion is 3 hours.

Uploaded by

Mahesh Sharma
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)
31 views

CBSE Class 12 Computer Science Sample Paper Set 2 for 2024-25 FREE PDF (1)

The document is a sample question paper for Class XII Computer Science, consisting of 37 compulsory questions divided into five sections with varying marks. It includes multiple-choice questions, programming tasks, and theoretical questions covering topics such as Python programming, SQL, and data structures. The total marks for the paper are 70, and the time allowed for completion is 3 hours.

Uploaded by

Mahesh Sharma
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/ 45

Class XII Computer Science Sample Paper – Set 2

Maximum Marks: 70 Time Allowed: 3 hours

General Instructions:

• This question paper contains 37 questions.


• All questions are compulsory. However, internal choices have been provided in some
questions. Attempt only one of the choices in such questions.
• The paper is divided into 5 Sections- A, B, C, D and E.
• Section A consists of 21 questions (1 to 21). Each question carries 1 Mark.
• Section B consists of 7 questions (22 to 28). Each question carries 2 Marks. Section C
consists of 3 questions (29 to 31). Each question carries 3 Marks.
• Section D consists of 4 questions (32 to 35). Each question carries 4 Marks.
• Section E consists of 2 questions (36 to 37).
• Each question carries 5 Marks. All programming questions are to be answered using
Python Language only.
• In case of MCQ, text of the correct answer should also be written.

Section A

Q. No. Questions Marks

1. State true or false: Do both the following represent the same list. 1

['a', 'b', 'c']

['c', 'a', 'b']

2. What is the full form of DDL? 1

www.vedantu.com 1
a) Data Definition Language

b) Dynamic Data Language

c) Detailed Data Language

d) Data Derivation Language

3. What is the best way to represent attributes in a large database? 1

a) All of these

b) Concatenation

c) Dot Representation

d) Relational-and

4. What are the possible outcome(s) executed from the following code? 1
Also specify the maximum and minimum values that can be assigned
to variable PICK.

import random

PICK= random.randint(0, 3)

CITY = ["DELHI", "MUMBAI", "CHENNAI", "KOLKATA"];

for I in CITY : for J in range(l, PICK) :

print(I, end = " ")

print()

5. Discuss the utility and significance of Tuples, briefly 1

www.vedantu.com 2
6. Computer communication signal which is in the form of the continuous 1
wave is called

a) modulation signal

b) Binary signal

c) digital signal

d) analog signal

7. To read the entire remaining contents of the file as a string from a file 1
object infi, we use

a) infi.readlines( )

b) display databases;

c) infi.readline( )

d) infi.read( )

8. Which of the following is correct to retrieve any character at index 'i' 1


in string 's'?

a) s.__getitem__(i)

b) s.getitem(i-1)

c) s.__getitem__(i-1)

d) s.getitem(i)

9. Which operator performs pattern matching? 1

www.vedantu.com 3
a) LIKE operator

b) BETWEEN operator

c) INTO operator

d) EXISTS operator

10. What will happen with the following code? 1

file1 = open ("c:\\users\\temp\\myfile.text",r)

file1.seek (2,-10)

print "The pointer is at",

file1.tell() file1.close()

11. State true or false: 1

In Python, a variable is a placeholder for data.

12. Process of inserting an element in a stack is called ________ 1

a) Evaluation

b) Create

c) Push

d) Pop

13. Differentiate between commands DROP TABLE and DROP VIEW in 1


SQL

www.vedantu.com 4
14. Internet is an example of ________ topology. 1

a) Mesh

b) Star

c) Tree

d) Bus

15. which of the following four code fragments will yield following 1
output?

Ziva

Diva

Riva

[Notice blank lines in between]

Select all of the function calls that result in this output.

a) print ('Ziva Diva Riva')

b) print(‘ZivaDivaRiva ')

c) print('Ziva\nDiva\nRiva')

d) print( 'Ziva \nDiva\nRiva ')

16. Which of the following join gives the intersection of two tables? 1

a) Inner join

b) Outer join

www.vedantu.com 5
c) Equi join

d) Fuller join

17. Find ODD parity bit for 11100011 1

a) 1

b) 2

c) 3

d) 0

18. Which of the following come under cyber crime? 1

i. Operating someone’s Internet banking account, without his


knowledge.

ii. Stealing a keyword from someone’s computer.

iii. Working on someone’s computer with his/her permission.

iv. None of these

a) Option (i)

b) Option (iii)

c) Option (iv)

d) Option (ii)

19. Assertion (A): While creating series by specifying data as a scalar 1


value, the index must be provided.

www.vedantu.com 6
Reason (R): The scalar value is repeated to match the length of the
index.

a) Both A and R are true and R is the correct explanation of A.

b) Both A and R are true but R is not the correct explanation of A.

c) A is true but R is false.

d) A is false but R is true.

20. Assertion (A): To store the data permanently into the file we use file 1
handling.

Reason (R): A file is a named location on a disk to store related


information.

a) Both A and R are true and R is the correct explanation of A.

b) Both A and R are true but R is not the correct explanation of A.

c) A is true but R is false

d) A is false but R is true.

21. Assertion (A): The python float() function returns a floating-point 2


number.

Reason (R): It takes one argument

a) Both A and R are true and R is the correct explanation of A .

b) Both A and R are true but R is not the correct explanation of A.

c) A is true but R is false

www.vedantu.com 7
d) A is false but R is true.

Section B

22. Give one advantage and one disadvantage of optical fiber cable 2
and coaxial cable used in communication.

23. Given below is a table Item in database Inventory. 2

ItemID ItemName Quantity UnitPrice

101 ABC 5 120

102 XYZ 7 70

103 PQR 8 65

104 XYZ 12 55

Riya created this table but forget to add column ManufacturingDate.


Can she add this column after creation of table? If yes, write the code
where user’s name and password are system and test respectively

24. i. What is the output of the following code? 2

dnry={0: 'a', 1: 'b', 2: 'c'}

for x, y in dnry:

print(x, y)

www.vedantu.com 8
ii. Write the corrected code for part (a) so that it prints keys and values
both.

OR

If a is (1, 2, 3)

i. what is the difference (if any) between a * 3 and (a, a, a)?

ii. is a * 3 equivalent to a + a + a?

iii. what is the meaning of a[1:1]?

iv. what's the difference between a[1:2] and a[1:1]?

25. Which data will get added in table Company by following code? 2

import mysql.connector

con = mysql.connector.connect(host = "localhost”,user =


"system”,passwd = "hello”,database = "connect”)

cur = con.cursor()

sql = "insert into Company(Name, Dept, Salary) values (%s, %s, %s)"

val = ("ABC", "DBA", 35000)

cur.execute(sql, val)

con.commit()

26. Write a program which will find all such numbers which are divisible 2
by 7 but are not a multiple of 5, between 200 and 300 (both included).

Or

www.vedantu.com 9
Underline the syntax errors in the following program

x = int(input("Enter first number:))

y = int(input("Enter second number:"))

z = int(input("Enter third number:")

a=x+b+z

print ("Result = ", b)

27. Write a program that check to see if the file name exists, it will give 2
you an error message, if not, it will create the file.

OR

Write a program to count the number of uppercase letters in a text file


"Article.txt".

28. How can you pass dictionary to function? 2

Section C

29. Consider a function with following header: 3

def info(object, spacing = 10, collapse = 1)

Here are some function calls given below. Find out which of these are
correct and which of these are incorrect stating reasons?

For correct function call statements, specify the argument values too.

i. info(obj1)

www.vedantu.com 10
ii. info(spacing=20)

iii. info(obj2, 12)

iv. info(obj11, object = obj12)

v. info(obj3, collapse = 0)

vi. info( )

vii. info(collapse = 0, obj3)

viii. info( spacing = 15, object = obj4)

OR

What will be the output of following programs?

I. num = 1

def myfunc():

return num

print(num)

print(myfunc())

print(num)

ii. num = 1

def myfunc():

www.vedantu.com 11
num = 10

return num

print(num)

print(myfunc())

print(num)

iii. num = 1

def myfunc():

global num

num = 10

return num

print(num)

print(myfunc())

print(num)

iv.

def display ():

print ("Hello", end = ' ')

display()

www.vedantu.com 12
print("there!")

30. i. A SQL table ITEMS contains the following columns: 3

INO, INAME, QUANTITY, PRICE, DISCOUNT

Write the SQL command to remove the column DISCOUNT from the
table.

ii. Categorize the following SQL commands into DDL and DML:

CREATE, UPDATE, INSERT, DROP

OR

Consider the following Query :

SELECT brand, MAX(price)

FROM product

GROUP BY brand

HAVING price > 100 ;

The above query is giving error.

i. Identify and list the error.

ii. Correct the error so that only those brands get listed that have a max
price more than 100.

iii. How will the corrected query's result be different from the following
query?

SELECT brand, price

www.vedantu.com 13
FROM product

WHERE price >100

GROUP BY brand;

31. From the program code given below, 3

identify the parts mentioned below :

1. def processNumber(x):

2. x = 72

3. return x + 3

4.

5. y = 54

6. res = processNumber(y)

Identify these parts: function header, function call, arguments,


parameters, function body, main program.

Or

Answer the questions (i) to (iv) based on the following:

class Book

char Bno[20];

protected:

www.vedantu.com 14
float Price;

public:

void GetB();

void ShowB();

};

class Member

char Mno[20];

protected:

char Name[20];

public:

void GetM();

void ShowM();

};

class Library : public Member, private Book

char Lname[20];

public:

void GetL();

www.vedantu.com 15
void ShowL();

};

void main()

Library L;

i. Which type of Inheritance out of the following is illustrated in the


above example?- Single Level Inheritance, Multilevel Inheritance,
Multiple Inheritance

ii. Write the names of all the data members, which are directly
accessible by the member function GetL() of class Library.

iii. Write the names of all the member functions, which are directly
accessible by the member function ShowL() of class Library.

iv. Write the names of all the members, which are directly accessible
by the object L of class Library declared in the main() function.

Section D

32. Write a program to implement a stack for these book details (bookno, 4
bookname). That is, now each item node of the stack contains two types
of information -a bookno and its name. Just implement push and
display operations.

Or

Write a program to print a string in reverse order.

www.vedantu.com 16
33. Write a point of difference between append (a) and write (w) modes in 4
a text file. Write a program in Python that defines and calls the
following user defined functions:

i. Add_Teacher() : It accepts the values from the user and inserts the
record of a teacher to a csv file 'Teacher.csv'. Each record consists of a
list with field elements as T_id, Tname and desig to store teacher ID,
teacher name and designation respectively.

ii. Search_Teacher() : To display the records of all the PGT


(designation) teachers.

34. Give output for following SQL queries as per given table(s) 4

Table: HOSPITAL

No. Name Age Department Dateofadm Charges Sex

1 Arpit 62 Surgery 21/01/98 300 M

2 Zarina 22 ENT 12/12/97 250 F

3 Kareem 32 Orthopedic 19/02/98 200 M

4 Arun 12 Surgery 11/01/98 300 M

5 Zubin 30 ENT 12/01/98 250 M

6 Ketaki 16 ENT 24/02/98 250 F

7 Ankita 29 Cardiology 20/02/98 800 F

www.vedantu.com 17
8 Zareen 45 Gynecology 22/02/98 300 F

9 Kush 19 Cardiology 13/01/98 800 M

10 Shilpa 23 Nuclear 21/02/98 400 F


Medicine

i. SELECT COUNT (DISTINCT Charges) FROM HOSPITAL;

ii. SELECT MIN (Age) FROM HOSPITAL WHERE Sex = "F";

iii. SELECT SUM (Charges) FROM HOSPITAL WHERE


Department = "ENT";

iv. SELECT AVG (Charges) FROM HOSPITAL WHERE


Dateofadm< {12/08/98}

or

Give output for following SQL queries as per given table(s) :

No. Name Age Department Date of Join Salary Sex

1 Jugal 34 Computer 10/01/97 12000 M

2 Sharmila 31 History 24/03/98 20000 F

3 Sandeep 32 Maths 12/12/96 30000 M

4 Sangeeta 35 History 01/07/99 40000 F

www.vedantu.com 18
5 Rakesh 42 Maths 05/09/97 25000 M

6 Shyam 50 History 27/06/98 30000 M

7 Shiv Om 44 Computer 25/02/97 21000 M

8 Shalakha 33 Maths 31/07/97 20000 F

i. SELECT COUNT (distinct department) FROM TEACHER;

ii. SELECT MAX (Age) FROM TEACHER WHERE Sex = "F";


30000 40000 25000 30000 21000 20000

iii. SELECT AVG(Salary) FROM TEACHER WHERE Dateofjoin<


{12/07/96};

iv. SELECT SUM (Salary) FROM TEACHER WHERE Dateofjoin <


{12/07/96}

35. Consider the table MobileMaster 4

M_Id M_Company M_Name M_Price M_Mf_Date

MB001 Samsung Galaxy 4500 2014-02-12

MB002 Nokia N1100 2250 2011-04-15

MB003 Sony Experia M 9500 2017-11-20

www.vedantu.com 19
MB004 Oppo SelfieEx 8500 2010-08-21

Write the Python code for the following

i. To display details of those mobiles whose price is greater than 8000.

ii. To increase the price of mobile Samsung by 2000.

Section E

36. Ravya Industries has set up its new center at Kaka Nagar for its office 5
and web based activities. The company compound has 4 buildings as
shown in the diagram below:

Center-to-Center Distances Between Buildings:

From Building To Building Distance

Harsh Building Raj Building 50 m

Raj Building Fazz Building 60 m

Fazz Building Jazz Building 25 m

www.vedantu.com 20
Jazz Building Harsh Building 170 m

Harsh Building Fazz Building 125 m

Raj Building Jazz Building 90 m

Number of Computers in Each Building:

Building Number of Computers

Harsh Building 15

Raj Building 150

Fazz Building 15

Jazz Building 25

i. What type of network will be formed if all blocks are connected?

ii. Suggest the most suitable place (i.e., block) to house the server of
this organisation with a suitable reason.

iii. Suggest the placement of the following devices with justification a.


Repeater b. Hub/Switch

iv. The organization is planning to link its front office situated in the
city in a hilly region where cable connection is not feasible, suggest an
economic way to connect it with reasonably high speed.

www.vedantu.com 21
37. Write SQL queries for (i) to (vii) on the basis of tables given below: 5

PRODUCTS

PID PNAME QTY PRICE COMPANY SUPCODE

101 DIGITAL 120 12000 RENBIX S01


CAMERA
14X

102 DIGITAL 100 22000 DIGI POP S02


PAD 11 i

104 PEN DRIVE 500 1100 STOREKING S01


16 GB

106 LED 70 28000 DISPEXPERTS S02


SCREEN 32

105 CAR GPS 60 12000 MOVEON S03


SYSTEM

Table: SUPPLIERS

SUPCODE SNAME CITY

S01 GET ALL INC KOLKATA

S03 EASY MARKET CORP DELHI

www.vedantu.com 22
S02 DIGI BUSY GROUP CHENNAI

i. To display the details of all the products in ascending order of product


names (i.e., PNAME).

ii. To display product name and price of all those products, whose price
is in the range of 10000 and 15000 (both values inclusive).

iii. To display the number of products, which are supplied by each


supplier, i.e., the expected output should be; S01 2 S02 2 S03 1

iv. To display the price, product name, and quantity (i.e., qty) of those
products which have a quantity of more than 100.

v. To display the names of those suppliers, who are either from DELHI
or from CHENNAI.

vi. To display the name of the companies and the name of the products
in descending order of company names.

vii. Obtain the outputs of the following SQL queries based on the data
given in tables PRODUCTS and SUPPLIERS above.

a. SELECT DISTINCT SUPCODE FROM PRODUCTS;

b. SELECT MAX (PRICE), MIN (PRICE) FROM PRODUCTS;

c. SELECT PRICE*QTY FROM PRODUCTS WHERE PID = 104;

d. SELECT PNAME, SNAME FROM PRODUCTS P, SUPPLIERS S


WHERE P. SUPCODE = S. SUPCODE AND QTY >100;

Or

www.vedantu.com 23
Write SQL queries for (i) to (iv) and find outputs for SQL queries (v)
to (viii), which are based on the tables:

Code BNAME TYPE

F101 The Priest Fiction

L102 German easy Literature

C101 Tarzan in the lost world Comic

F102 Untold story Fiction

C102 War heroes Comic

TABLE: MEMBER

MNO MNAME CODE ISSUEDATE

M101 RAGHAV SINHA LI 02 2016-10-13

M103 S ARTHAKJ OHN FI 02 2017-02-23

M102 ANISHA KHAN C101 2016-06-12

www.vedantu.com 24
i. To display all details from table MEMBER in descending order of
ISSUEDATE.

ii. To display the BNO and BNAME of all Fiction Type books from the
table Book.

iii. To display the TYPE and number of books in each TYPE from the
table BOOK.

iv. To display all MNAME and ISSUEDATE of those members from


table MEMBER who have books issued (i.e., ISSUEDATE) in the year
2017.

v. SELECT MAX (ISSUEDATE) FROM MEMBER

vi. SELECT DISTINCT TYPE FROM BOOK

vii. SELECT A.CODE, BNAME, MNO. MNAME FROM BOOK A.


MEMBER B WHERE A.CODE= B.CODE

viii. SELECT BNAME FROM BOOK WHERE TYPE NOT IN


("FICTION", "COMIC")

www.vedantu.com 25
Answer Key

Section A

1. b) False

2. (a) Data Definition Language

3. (a) Data Definition Language

4. c) DELHI

MUMBAI

CHENNAI

KOLKATA

5. The tuple is similar to lists but the value of the items stored in the list can be changed,
whereas the tuple is immutable, and the value of the items stored in the tuple cannot be
changed.

6. d) analog signal

7. d) infi.read( )

8. (a) s.__getitem__(i)

9. a) LIKE operator

10. The code will open the file myfile.txt first by open function and then by seek() method
place the pointer 10 bytes before the end of file. Lastly, it will tell the position of the file
pointer from the starting of the file.

11. b) False

12. (c) Push

www.vedantu.com 26
13. DROP TABLE statement is used to delete the table and all its data from the database
entirely. The syntax for DROP TABLE is DROP TABLE ;

DROP VIEW Removes an existing view from a database. DROP VIEW statement is used to
remove a view or an object view from the database. The syntax for DROP VIEW is DROP
VIEW ;

14. a) Mesh

15. d) print( 'Ziva

\nDiva

\nRiva ')

Explanation: p

rint( 'Ziva

\nDiva

\nRiva ')

16. (a) Inner join

17. d) 0

18. a) Option (i)

19. c) A is true but R is false

20. b) Both A and R are true but R is not the correct explanation of A.

21. d) A is false but R is true

www.vedantu.com 27
Section B

22.

Optical Fiber Cable:

Advantage: It is free of electrical noise and interference.

Disadvantage: It is an expensive communication medium.

Coaxial cable:

Advantage: It provides a cheap means of transporting multi-channel television signals


around metropolitan areas.

Disadvantage: When using coaxial cables over long distances, signal loss is a disadvantage.

23.

Yes, she can add new column after creation of table.

mycon = mysql.connector.connect(host = "localhost",user = "system",passwd = "test",datab


cursor = mycon.cursor()

cursor.execute("ALTER TABLE Item ADD ManufacturingDate Date NOT NULL")


mycon.close()

24.

i. The above code will produce Error as we can iterate only on keys in a dictionary.
Thus the line:

www.vedantu.com 28
for x, y in dnry:

is wrong and it will give error.

ii. dnry={0: 'a', 1: 'b', 2: 'c'}

for x in dnry:

print(x, dnry[x])

# output for this will be:

0a

1b

2c

Or

i. Expression a * 3 will give a tuple while (a, a, a) will give a nested tuple :

>>> a = (1, 2, 3)

>>> a * 3 (1, 2, 3, 1, 2, 3, 1, 2, 3)

>>> (a, a, a)

((1, 2, 3), (1, 2, 3), (1, 2, 3))

ii. Yes iii. Empty tuple ( )

iv. a [1:2] will give a tuple with one item while a[1:1] will give an empty tuple.

www.vedantu.com 29
25.

"ABC", "DBA", 35000

26.

l = []

for i in range(200, 300):

if(i%7==0) and (i%5!=0)

l.append (str(i))

print(','.join(l))

x = int(input("Enter first numbe r : "))

y = int(input("Enter second number:"))

z = int(input("Enter third number:”))

a=x+y+z

print("Result = ", a)

27.

import os

if os.path.isfile('test.txt’):

print ("You are trying to create a file that already exists!")

www.vedantu.com 30
else :

f = open("text.txt",'w’)

If the text file test exists, the program will print "You are trying to create a file that already
exists!" else the file is opened in write mode, to create a new file with length 0.

OR

fileObject = open("Article.txt",r)

count = 0

str = fileObject.read()

for char in str: if char.isupper():

count += 1

fileObject.close()

print ("Number of uppercase characters are ", count)

28.

Dictionary can also be pass to the function by following example. e.g.

def dic(a):

for i in a:

print(i , ":", a [i])

dic({1:"One", 2:"Two", 3:"Three"})

www.vedantu.com 31
Output

1 : One

2 : Two

3 : Three

Section C

29.

i. Correct - obj1 is for positional parameter object; spacing gets its default value of 10 and
collapse gets its default value of 1. The function call would become info(obj, 10, 1).

ii. Incorrect - Required positional argument (object) missing; required arguments cannot be
missed. This function call is incorrect.

iii. Correct - Required parameter object gets its value as obj2; spacing gets value 12 and for
skipped argument collapse, default value 1 is taken. The function call would become
info(obj2, 12, 1), which is correct.

iv. Incorrect - Same parameter object is given multiple values - one through positional
argument and one through keyword(named) argument. The same parameter cannot have
multiple values in a function call. Therefore, this function call is incorrect.

v. Correct - Required parameter object gets its value as obj3; collapse gets value 0 and for
skipped argument spacing, default value 10 is taken. The function call would be info(obj3,
10,0), which is correct.

vi. Incorrect - Required parameter object's value cannot be skipped. Therefore, this function
call is incorrect.

www.vedantu.com 32
vii. Incorrect - Positional arguments should be before keyword arguments. obj3 should be
passed before spacing and collapse values. viii. Correct - Required argument object gets its
value through a keyword argument.

OR

These are the outputs to the above code segments:

i.

ii.

10

iii.

10

10

iv. Hello there!

www.vedantu.com 33
30.

i. Removing the Column "DISCOUNT": To remove the column named "DISCOUNT" from
the existing "ITEMS" table, we can use the following SQL command:

ALTER TABLE ITEMS DROP COLUMN DISCOUNT;

ii. Categorizing SQL Commands:

DDL (Data Definition Language):

CREATE: Used to create a new database or its objects.

DROP: Used to delete objects (e.g., tables) from the database.

DML (Data Manipulation Language):

INSERT: Used to add new records to a table.

UPDATE: Used to modify existing records in a table.

OR

i. The condition price > 100 with HAVING clause is error because with group by groups of
records get created that contain the summary result and price > 100 is applicable on
individual records and not on group of records.

ii. SELECT brand, MAX(price) FROM product GROUP BY brand HAVING MAX(price) >
100 ;

iii. The corrected query will return only those groups where MAX(price) > 100. But the
given query will first extract records with price > 100 and then group them on the basis of
column brand.

www.vedantu.com 34
31.

Description Code/Value Location

Function header def processNumber(x): in line 1

Function call processNumber(y) in line 6

Arguments y in line 6

Parameters x in line 1

Function body x = 72 in lines 2 and 3

return x + 3

Main program y = 54 in lines 5 and 6

res = processNumber(y)

OR

i. Multiple Inheritance

ii. Lname of class Library

Name of class Member

Price of class Book

iii. GetL() of class Library

www.vedantu.com 35
GetM(), ShowM() of class Member

GetB(), ShowB() of class Book

iv. GetL(), ShowL() of class Library

GetM(), ShowM() of class Member

Section D

32. Implementation of stack for push and display operation:

def isEmpty(stk):

if stk==[ ]:

return True

else:

return False

def pushbook(stk, item):

stk. append (item)

top=len(stk)-1

def displaybook(stk):

if isEmpty(stk):

print “Stack Empty”

else: top = len(stk)-1

www.vedantu.com 36
print “Book No----- Book Name”

for a in range (top, -1,-1)

print stk[a].split( )

#main

stack = [ ]

top = None

while True:

print “Books”

print “1. Add a book”

print “2. Display list”

print “3. Exit”

ch=int (row_input(“Enter your choice 1-3:”))

if ch == 1:

bno = row_input(“Enter Book No.”)

bname = row_input(“Enter Book Name”)

item = [bno, bname]

pushbook(item, stk)

row_input()

elif ch == 2:

www.vedantu.com 37
displaybook(stk)

row_input()

elif ch==3:

break else:

print “Invalid choice!”

row_input( )

or

To print a string in Reverse order:

def pushstack(stack, ch):

stack, append(ch)

top=len(stack)-1

return

def popstack (stack):

if isempty(stack):

return else top=len(stack)-1

for a in range(top, -1, -1)

print stack[a],

return

def isempty (stack):

www.vedantu.com 38
if stack==[]:

else:

return True else:

return False

#.....main.....

str=[]

top=None

str=raw_input(“Enter a string”)

while a in str:

pushstack(stk, str)

print “------ Reverse-------“

popstack(stk)

33.

Difference between append (a) and write (w) modes in a text file:

a (append) mode - To open the file to write the content at the bottom(or end) of existing
content. It also creates the file, if it does not exist.

whereas

w (write) mode - To create a new file to write the content in it. It overwrites the file, if it
already exists.

www.vedantu.com 39
import csv

def Add_Teacher():

fout=open("Teacher.csv","a",newline="\n")

T_id=int(input("Enter Teacher id: "))

Tname=input("Enter Teacher name: ")

desig=input("Enter Designation: ")

rec=[T_id,Tname,desig]

csvw=csv.writer(fout)

csvw.writerow(rec)

fout.close()

def Search_Teacher():

fin=open("Teacher.csv")

csvr=csv.reader(fin)

for record in csvr:

if record[2]=="PGT":

print(record)

fin.close()

Add_Teacher()

Search_Teacher()

www.vedantu.com 40
34.

i. COUNT (DISTINCT Charges)

ii. MIN (Age)

16

iii. SUM (Charges)

750

iv. AVG (Charges)

385

OR

OUTPUT

i. 3

ii. 35

iii. 0

iv. 0

www.vedantu.com 41
35.

i. import mysql.connector as mydb


mycon=mydb.connect(host="localhost",user="root",passwd="system",database="Admin
cursor=mycon.cursor()

sql="SELECT * FROM MobileMaster WHERE M_Price>8000"

try:

cursor.execute(sql)

display=cursor.fetchall()

for i in display:

print (i)

except: mycon.rollback()

mycon.close()

ii. import mysql.connector as mydb


mycon=mydb.connect(host="localhost",user="root",passwd="system",database="Admin
cursor = mycon.cursor()

sql = "UPDATE MobileMaster SET M_Price=M_Price+2000 WHERE M_Company='S try:

cursor.execute(sql)

mycon.commit()

except:

mycon.rollback()

mycon.close()

www.vedantu.com 42
Section E

36.

i. The most suitable place/block to house the server of this organisation would be Raj
Building, as this block contains the maximum number of computers, thus decreasing the
cabling cost for most of the computers as well as increasing the efficiency of the maximum
computers in the network.

ii. a. Raj Building

b. In the layouts, a hub/switch each would be needed in all the buildings, to interconnect the
group of cables from the different computers in each block.

iii. The type of network that shall be formed to link the sale counters situated in various parts
of the same city would be a MAN because MAN (Metropolitan Area Networks) are the
networks that link computer facilities within a city.

37.

i. SELECT * FROM PRODUCTS ORDER BY PNAME ASC; (* bydefault show all the
values)

ii. SELECT PNAME, PRICE FROM PRODUCTS WHERE ((PRICE = > 10000) AND
(PRICE = < 15000));

iii. SELECT SUPCODE, COUNT (PID) FROM PRODUCTS GROUP BY SUPCODE;

iv. SELECT PRICE, PNAME, QTY FROM PRODUCTS WHERE (QTY > 100);

v. SELECT SNAME FROM SUPPLIERS WHERE ((CITY = "DELHI") OR (CITY =


"CHENNAI"));

vi. SELECT COMPANY, PNAME FROM PRODUCTS ORDER BY COMPANY DESC;

www.vedantu.com 43
vii. a. S03

b. 28000 1100

c. 550000

d.

PNAME SNAME

DIGITAL CAMERA 14X GETALL INC

PENDRIVE 16 GB GETALL INC

OR

i. SELECT * FROM MEMBER ORDER BY ISSUEDATE DESC

ii. SELECT Code, BNAME FROM BOOK WHERE TYPE 'Fiction'

iii. SELECT COUNT(*), TYPE FROM BOOK GROUP BY TYPE

iv. SELECT MNAME, ISSUEDATE FROM MEMBER WHERE ISSUEDATE Like


'2017 %'

v. MAX (ISSUE DATE) 2017-02-23

vi. DISTINCT (TYPE)

Fiction

Literature

www.vedantu.com 44
Comic

vii.

CODE BNAME MNO MNAME

LI02 German easy M101 RAGHAV


SINHA

F102 Untold Story M103 SARTHAK


JOHN

C101 Tarzan in the M102 ANISHA


lost Worls KHAN

iii. BNAME German easy

www.vedantu.com 45

You might also like