0% found this document useful (0 votes)
58 views55 pages

Sure Shot Questions 2024-25 Final

The document contains a series of sure-shot questions for the Computer Science subject for Class XII, covering various topics such as identifiers, data types, expressions, and file handling in Python. It includes multiple-choice questions, true/false statements, and fill-in-the-blank questions aimed at assessing students' understanding of programming concepts. The questions are designed for the academic session 2024-25 at PM SHRI Kendriya Vidyalaya O.F. Chanda.

Uploaded by

chaitallp755
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)
58 views55 pages

Sure Shot Questions 2024-25 Final

The document contains a series of sure-shot questions for the Computer Science subject for Class XII, covering various topics such as identifiers, data types, expressions, and file handling in Python. It includes multiple-choice questions, true/false statements, and fill-in-the-blank questions aimed at assessing students' understanding of programming concepts. The questions are designed for the academic session 2024-25 at PM SHRI Kendriya Vidyalaya O.F. Chanda.

Uploaded by

chaitallp755
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

PM SHRI KENDRIYA VIDYALAYA O.F.

CHANDA
SURE-SHOT QUESTIONS
SUBJECT: COMPUTER SCIENCE (083)
CLASS-XII
SESSION 2024-25

1 MARK QUESTIONS

1. Find valid identifier among the following:


a) with b) radius_circle c) 5average d) total+tax

2. Find the invalid identifier from the following:


a) def b) For c)_bonus d) First_Name

3. Write the valid identifiers among the following:


bool, and, 8digit, min value, Else

4. Which among the following, is/are correct identifier(s):


salary, student-fee, continue, amount3, my . data

5. Write the type/name of token for the following:


i) 83.95
ii) ==

6. Write type of token for the following:


i) 88.7
ii) continue

7. State True or False:


“Variable declaration is implicit in Python.”

8. Line indentation is rigidly enforced in python:


a) True b) False

9. Which of the following is an invalid datatype in Python?


a) Set b) None c) Integer d) Real

10. Which type of value does input( ) return?

11. Write name of python module which is to be imported in program to use the
following functions:
i) ceil ( )
ii) date( )

12. Name the python library need to be imported to invoke following functions:
i) randint( )
ii) date( )

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 1


13. Consider the given expression:
not True and False or True
Which of the following will be the correct output if the given expression is
evaluated?
a) True b) False c) NONE d) NULL

14. Consider the given expression:


not 12 > 6 and 7 < 17 or not 12 < 4
Which of the following will be the correct output if the given expression is
evaluated?
a) True b) False c) NONE d) NULL

15. Given the following dictionaries


dict_exam={"Exam":"AISSCE", "Year":2025}
dict_result={"Total":500, "Pass_Marks":165}
Which statement will merge the contents of both dictionaries?
a) dict_exam.update(dict_result)
b) dict_exam + dict_result
c) dict_exam.add(dict_result)
d) dict_exam.merge(dict_result)

16. Suppose a tuple Tup is declared as Tup = (12, 15, 63, 80)
Which of the following is incorrect?
a) print(Tup[1]) b) Tup[2] = 90
c) print(min(Tup)) d) print(len(Tup))

17. Which of the following statements will create a tuple ?


a) Tp1 = (“a”, “b”)
b) Tp1= (3) * 3
c) Tp1[2] = (“a”, “b”)
d) None of these

18. Select the correct output of the code:


a = "Year 2022 at All the best"
a = a.split('2')
b = a[0] + ". " + a[1] + ". " + a[3]
print (b)
a) Year . 0. at All the best
b) Year 0. at All the best
c) Year . 022. at All the best
d) Year . 0. at all the best

19. Select the correct output of the given code.


d1 = {“abc” : 5, “def” : 6, “ghi” : 7}
print (d1[0])

a) abc b) 5 c) {“abc”:5} d) Error

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 2


20. Select the correct output of the code:
K=[5,7,8, [10,4], 11,2]
print(len(K))

a) 7 b) 6 c) 3 d) 5

21. Consider the following list : L=[23,7,38,82,54,45,10,91]


What will be the output of the following code:
print(L[-3 : -8 : -3])

a) [45,38] b) [38,45] c) [38,82,54,45] d) [ ]

22. What will be the output of the following:


str = “Cricket World Cup in Australia”
str2 = str[:7] + ” “ + str[18:] + “.”
print(str2)

23. Select the correct output of the following code:


S = "Motivational thought"
S.find("hou", 4, 13)

a) True b) 4 c) 14 d) -1

24. Select the correct output of the code:


S1="AISSCE PRACTICE PAPER"
S2=S1.split( )
print(type(S2))

a) <class ‘tuple’>
b) <class ‘int’>
c) <class ‘str’>
d) <class ‘list’>

25. Select the correct output of the code:


A = [17, 24, 15, 30]
A.insert( 2, 33)
print ( A [-4])
a) 24 b) 33 c) 15 d) 17

26. Which of the following mode in file opening statement results or generates an
error if the file does not exist?
a) a+ b) r+ c) w+ d) None of the above

27. What is meaning of "w+" mode:


a) Creating a fresh file only
b) Open an existing file, first read then write
c) Open an existing file, first write then read
d) Open a new fresh file, writes data in the end of file

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 3


28. ________________ method is used to Transfer data from buffer to permanent
store in data file handling.

29. Which among the following is not a function of tuple?


a) count ( ) b) split( ) c) max( ) d) min( )

30. Fill in the blank:


______ command is used to remove primary key from the table in SQL.
a) update b) remove c) truncate d) drop

31. Fill in the blank:


The………………… keyword is used to select rows that match specified pattern of
characters in MySQL.

32. Which of the following statement(s) would give an error after executing the
following code?
G=10,20,30,40 #statement-1
print(G**2) #statement-2
G[1]=35 #statement-3
R=G+(22,) #statement-4
print(R) #statement-5

a) statement -1 and statement-5


b) Statement-2 and statement-3
c) Statement-1 and statement-4
d) Statement-1 only

33. Which of the following statement(s) would give an error after executing the
following code?
S="Welcome to class XII" # Statement 1
print(S) # Statement 2
S="Thank you" # Statement 3
S[0]= '@' # Statement 4
S=S+"Thank you" # Statement 5

a) Statement 3
b) Statement 4
c) Statement 5
d) Statement 4 and 5

34. The correct syntax of dump( ) is:


a) file_object=dump(data_object)
b) file_object.dump(data_object)
c) pickle.dump(data_object,file_object)
d) pickle.dump(file_object,data_object)

35. The correct syntax of seek( ) is:


a) file_object.seek(offset [, reference_point])

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 4


b) seek(offset [, reference_point])
c) seek(offset, file_object)
d) seek.file_object(offset)

36. A result set is extracted from the database using a cursor object by giving the
following statement:
records=mycursor.fetchall( )
What will be the data type of ‘records’ after the execution of above statement?

37. Which among the following is correct output after evaluation of the given
expression:
import math
math.ceil(-6.6)

a) -6 b) -7 c) 6.6 d) -5

38. Which among the following is correct output after evaluation of the given
expression:
>>> 12 - (3 % 4) // 2 + 6 ** 2

a) 46.5 b) 36 c) 12 d) 47

39. What will the following expression be evaluated to in Python?


print(15.0 / 4 + (8 + 3.0))

a) 14.75 b)14.0 c) 15 d) 15.5

40. What will be correct output for the following:


R= (4.5, 5), (5,4), (8.2,7), (8,7,3)
print(max(R))

a) Error b) (8.2, 7) c) (8,7,3) d) (4.5,5,8.2,8)

41. What is the length of the tuple shown below?


t=(((('a',1),'b','c'),'d',2),'e',3)

a) 8 b) 4 c) 1 d) 3

42. Which command is used for counting the number of rows in a database?
a) count b) fetchmany c) rowcount d) countrecord

43. readlines( ) method reads the data from the file and returns it into:
a) string b) list c) tuple d) file

44. Consider the following dictionary:


machine = {‘id’:1001, ‘name’:‘UPS’, ‘capacity’:5000, ‘rate’:15000.00}
Write a statement to change the capacity to 4500.

45. Fill in the blank:

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 5


_________ is a non-key attribute, whose values are derived from the primary key
of some other table.
a) Primary Key
b) Foreign Key
c) Candidate Key
d) Alternate Key

46. Which function in SQL is used to count the total number of records regardless of
NULL from table in a database?
a) sum(*)
b) total(*)
c) count(*)
d) count( )

47. To establish a connection between Python and SQL database, connect() is used.
Which of the following arguments may not necessarily be given while calling
connect() ?
a) host
b) database
c) user
d) password

48. After executing any DML command from Python in Python-MySQL connectivity,
following is necessary to execute in order to make the changes permanent in
MySQL:
a) save()
b) store()
c) commit()
d) update()

49. Fill in the blank:


The SELECT statement when combined with __________ clause, returns records
without repetition.
a) DESCRIBE
b) UNIQUE
c) DISTINCT
d) NULL

50. Fill in the blank:


In MySQL, The attribute which is a candidate key but not a primary key is known
as _______________________.

51. Ravish created a database namely BUSINESS. Now he wants to create a table in it.
For this he needs to open the database that he has created. Write SQL command
to open the database that is created by Ravish.

52. Fill in the blank:


______is a communication methodology designed to deliver both voice

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 6


and multimedia communications over Internet protocol.
a) VoIP b) SMTP c) PPP d) HTTP

53. Fill in the blank:


A ………………………… is a networking device that connects computer in a network by
using packet switching to receive and forward data to the destination.
a) Router b) Repeater c) Switch d) Gateway

54. Which of the following protocols is used for remote login:


a) VoIP
b) HTTP
c) IMAP
d) TELNET

55. Computers connected by a network across different cities is an example of


……………………………….

56. Which among the following transmission mediums provide efficient and the fastest
communication:
a) Twisted pair Cable
b) Optical Fiber Cable
c) Co-axial Cable
d) Telephone cable

57. Bluetooth is example of which type of network:


a) LAN b) MAN c) WAN d) PAN

58. Expand the following terms:


i. XML
ii. URL

59. State True or False:


“Identifiers are names used to identify a variable, function in a program”.

60. Which of the following is a valid keyword in python?


a) false b) return c) non_local d) none

61. Given the following Tuple


Tup= (10, 20, 30, 50)
Which of the following statements will result in an error?
a) print(Tup[0]) b) Tup.insert (2,3)
c) print(Tup[1:2]) d) print(len(Tup))

62. Consider the given expression :


5<10 and 12>7 or not 7>4
Which of the following will be the correct output, if the given expression is
evaluated?
a) True b) False c) NONE d) NULL

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 7


63. Which of the following mode keeps the file offset position at the end of the
file?
a) r+ b) r c) w d) a

64. The file offset position for <r> is the:


a) beginning of the file
b) end of the file
c) middle of the file
d) the point where it was left when last accessed

65. Which of the following operators will return either True or False ?
a) += b) = c) != d) *=

66. Which of the following statement(s) would give an error after executing
the following code ?
Stud= { "Murugan": 100, "Mithu": 95} # Statement 1
print (Stud[95]) # Statement 2
Stud ["Murugan"]=99 # Statement 3
print(Stud.pop()) # Statement 4
print(Stud) # Statement 5

a) Statement-2 b) Statement-3
c) Statement-4 d) Statement-2 and 4

67. The syntax of seek() is :


File_object.seek(offset [,ref_point])
What is the default value of ref_point?
a) 3 b) 2 c) 1 d) 0

68. Fill in the blank:


___ clause is used in SQL query to display data in a sorted
form with respect to a specified column.
a) WHERE b) ORDER BY c) HAVING d) DISTINCT

69. _____________ is used for point-to-point communication or unicast


communication such as radar and satellite.
a) Infrared b) Bluetooth c) Microwaves d) Radiowaves

70. The modem at the sender’s computer end acts as a ____________.


a) Model b) Modulator c) Demodulator d) Convertor

71. What will be the output of the following statement:


print(4 and 17//3**2)
(a) 4 (b) True (c) 1 (d) 25

72. Which among the following python modules has fabs() function:
(a) random (b) statistics (c) pickle (d) math

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 8


73. Exceptions are handled in:
(a) try block (b) except block
(c) finally block (d) else block

74. pickle module in python is used for:


(a) It moves the file pointer at specified location
(b) To convert a text file into binary file
(c) It returns the current position of the file object
(d) Serializing and deserializing any python object structure

75. State weather the following statement is True or False:


Every record in a CSV file is stored in reader object in the form of a list using
reader() method.

76. Python uses __________ data type for creating and managing stack:
(a) tuple (b) list (c) dictionary (d) None of them

77. State True or False:


“Every function in python returns some value.”

78. Write output after evaluation of the given expression:


not 6 > 5 and 4 != 4.0 or not 10 < 15

79. When will the else part of try-except-else be executed?


a) always
b) When an exception occurs
c) When no exception occurs
d) when an exception occurs in to except block

80. Find the output of a given expression:


import math
3//-5+math.pow(3,2)-6%4
a) 6.0 b) 4.0
c) -2 d) 7

81. Consider the following list : Z=[4,40,60,75,23,45,25]


What will be the output of the following code:
print(Z[-2 : 1 : -3])
a) [ ] b) [45, 60] c) [45, 60, 4] d) Error

82. Which of the following python statement will bring the read pointer to 10
position backward from end of the file containing 90 characters, if file opened in
binary mode:
a) File.seek(10,0) b) File.seek(-10,2)
c) File.seek(-10,1) d) File.seek(10,2)

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 9


83. State True or False:
All functions in Python are required to take at least one argument.

84. Write output for the following python statements:


>>>s="hello"
>>>s.count('') #empty string as an argument

85. Which among the following keywords is used to catch exceptions in Python?
a) try b) except c) catch d) finally

86. Which of the following is used to write data to a CSV file?


import csv
with open('file.csv', 'w', newline='') as file:
w = ______________ #to write data

a) pickle.write(file) b) file.writer(csv)
c) csv.dump(file) d) csv.writer(file)

87. What is the main principle behind a stack data structure?


a) Last In, First Out (LIFO) b) Random Access
c) Sorted Order d) First In, First Out (FIFO)

88. Fill in the blank:


______ is a communication methodology designed to deliver both voice and
multimedia communications over Internet protocol.
a) VoIP b) SMTP c) PPP d) HTTP

89. State True or False:


The Python interpreter handles logical errors during code execution.

90. Identify the output of the following code snippet:


text = "PYTHONPROGRAM"
text=text.replace('PY','#')
print(text)

(A) #THONPROGRAM (B) ##THON#ROGRAM (C) #THON#ROGRAM (D)


#YTHON#ROGRAM

91. Which of the following expressions evaluates to False?


(A) not(True) and False (B) True or False
(C) not(False and True) (D) True and not(False)

92. What is the output of the expression?


country='International'
print(country.split("n"))
(A) ('I', 'ter', 'atio', 'al') (B) ['I', 'ter', 'atio', 'al']
(C) ['I', 'n', 'ter', 'n', 'atio', 'n', 'al'] (D) Error

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 10


93. Write the missing statement to complete the following code:
file = open("example.txt", "r")
data = file.read(100)
____________________ #Move the file pointer to the beginning of the file
next_data = file.read(50)
file.close()

94. State whether the following statement is True or False:


The finally block in Python is executed only if no exception occurs in the try block.

95. Which SQL command can change the degree of an existing relation?

96. In which datatype the value stored is padded with spaces to fit the specified length.
(A) DATE (B) VARCHAR (C) FLOAT (D) CHAR

97. Which aggregate function can be used to find the cardinality of a table?
(A) sum() (B) count() (C) avg() (D) max()

98. Which switching technique breaks data into smaller packets for transmission,
allowing multiple packets to share the same network resources.

99. Consider the statements given below and then choose the correct output from the
given options:
pride="General Elections@2024"
L=pride.split(‘e’)
print(L[::-2])

a) ['Elections@2024'] b) ['ral El']


c) ['General'] d) ['ctions@2024', 'n']

100. State True or False:


“While defining a function in python, the positional parameters in the function
header must always be written after the default parameter.”

101. Consider a text file “lyrics.txt” has the following text:


Saare jahaan se achchha
Which among the following will be correct output after executing the given python
code:
f=open("lyrics.txt","r")
f.read(4)
f.seek(2)
print(f.read(3))
f.close()

a) jah b) Saa c) e j d) are

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 11


102. If a table which has one Primary key and two alternate keys. How many
Candidate keys will this table have?
(A) 1 (B) 2 (C) 3 (D) 4

103. Write the missing statement to complete the following code:


f = open("Essay.txt", "r")
data = f.read(80)
cur_pos= _________ # Get the current position of the file pointer
print(“Current position is: ”, cur_pos)
f.close()

104 What will be the output of the following code?


p=6
def Demo():
global p
p**=2
print(p,end='+')
Demo()
print(p,end='@')

105. The degree and cardinality of a table named SONG are 2 and 4, respectively. The
degree and cardinality of another table named SINGER are 3 and 5, respectively.
There is one common field in both tables. After performing the Cartesian product
of both tables, what will be the new degree and cardinality of the resultant table?
A. 4 and 20 B. 5 and 20
C. 5 and 9 D. 4 and 9

106. Which function in SQL is used to count the total number of records regardless of
NULL from table in a database?
a) sum(*)
b) total(*)
c) count(*)
d) count( )

107. Which error occurs when a variable is used before being initialized in python?

A. Syntax error B. Logical error


C. NameError D. TypeError

108. State True or False:


“The is operator checks the identity of two variables, not the equality of
their values.”

109. Identify the output of the following code snippet:


thought="work is worship"
p=thought.partition("or")
print(p)
A. [‘work’, ‘is’, ‘worship’]
B. ('w', 'or', 'k is worship')

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 12


C. [‘w’, ‘or’, ‘k is worship’]
D. (‘work’, ‘is’, ‘worship’)

110. Which of the following expressions evaluates to True?


A. False or not True==1
B. not 3>4 and 5 and False
C. 4**3 and 0 or False
D. 12!=5 or not True

111. State True or False:


The try block in Python can contain multiple except blocks to handle different
types of exceptions.

112. A result set is extracted from the database using a cursor object by giving the
following statement:
records=mycursor.fetchall( )
What will be the data type of records,after the execution of above statement?
A. tuple B. string
C. dictionary D. list

ASSERTION AND REASONING BASED QUESTIONS: (01 Mark)


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

1. Assertion (A):- If the arguments in function call statement match the number and
order of arguments as defined in the function definition, such arguments are called
positional arguments.
Reason(R):- During a function call, the argument list first contains default
argument(s) followed by positional argument(s).
2. Assertion (A): CSV (Comma Separated Values) is a file format for data storage which
looks like a text file.
Reason (R): The information is organized with one record on each line and each field
is separated by comma.
3. Assertion (A): Function invoked by its name.
Reason (R): A function is a named block of statements.
4. Assertion (A): The csv files can only take comma as delimiter.
Reason (R): The comma is the default separator character but other popular
delimiters include the tab (\t), colon (:) and semi-colon (;)
5. Assertion (A): Inside a function if we make changes in a string it will reflect back to
the original string.
Reason (R): String is an immutable datatype and it is called by value.
Mark the correct choice as :
6. Assertion (A): Identifiers are the fundamental building blocks of a program.
Reason (R) : Identifiers always start with digit or underscore.

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 13


7. Assertion(A): In the if-elif ladder, it may possible that no block is executed.
Reason(R): If no condition is true in if-else ladder then no block will be executed.
8. Assertion(A): A loop is simply exit when condition of the loop triggered False.
Reason(R): The loop condition depends upon the value of counter variable of the
loop.
9. ASSERTION (A): writer() is a function of csv module which writes data into csv files.
REASON (R): Since csv are flat files and before writing onto them, the data must be
in delimited form, it is important to convert the received data into the form
appropriable for csv files.
10. Assertion(A): A stack is a FIFO structure.
Reason(R): Any new element pushed into the stack always gets positioned at the
index after the last existing element in the stack.
11. Assertion (A): CSV (Comma Separated Values) is a file format for data storage which
looks like a text file.
Reason (R): The information is organized with one record on each line and each field
is separated by comma.
12. Assertion (A): There is no need to close a file explicitly using close() method if we
open a file using with clause.
Reason (R): While closing the file, the system frees up all the resources like
processor and memory allocated to it.
13. Assertion (A): IP addresses are unique identifiers for devices on a network.
Reason (R): Two devices on the same network can have the same IP address without
any issues.
14. Assertion (A): Positional arguments in Python functions must be passed in the exact
order in which they are defined in the function signature.
Reasoning (R): This is because Python functions automatically assign default values
to positional arguments.
15. Assertion (A): A SELECT command in SQL can have both WHERE and HAVING
clauses.
Reasoning (R): WHERE and HAVING clauses are used to check conditions, therefore,
these can be used interchangeably.
16. Assertion(A): Python standard library consists of number of modules.
Reasoning(R): A function in a module is used to simplify the code and avoids
repetition.
17. Assertion (A): A dictionary is indexed by keys and a key cannot be changed in a
dictionary.
Reason (R) : A dictionary is ordered and immutable data type.
18. Assertion (A): The return statement in a Python function is optional.
Reasoning (R): If no return statement is used, the function returns None by default.
19. Assertion (A): In SQL, the GROUP BY clause is used to arrange identical data into
groups.
Reason (R): The GROUP BY clause is mandatory when using aggregate functions like
SUM() or AVG().

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 14


02 MARKS QUESTIONS
1. Rao has written a code to input a number and check whether it is prime or not. His
code is having errors. Rewrite the correct code and underline the corrections made.
def prime( ):
n=int(input("Enter number to check :: ")
for i in range (2, n//2):
if n%i=0:
print("Number is not prime \n")
break
else:
print("Number is prime \n’)
2. Rewrite the following code in python after removing all syntax error(s). Underline
each correction done in the code.

str=list("Python Program@2021')
for Y is range(len(str)-1):
if Y==7:
str[Y]=str*2
elif(str[Y].isupper():
str[Y]=str*3
elif(str[Y].isdigit()):
str[Y]='D'
print(str)
3. Following code is having some errors. Rewrite the code after correcting and
underlining each correction:
x == 20
def printme():
y = x + 10
sum = 0
for i in range(x,y)
if i%3=0:
sum=sum+i+1
Elseif:
sum += 2
return(sum)
4. The code provided below is intended to swap the first and last elements of a given
tuple. However, there are syntax and logical errors in the code. Rewrite it after
removing all errors. Underline all the corrections made.
def swap_first_last(tup)
if len(tup) < 2:
return tup
new_tup = (tup[-1],) + tup[1:-1] + (tup[0])
return new_tup
result = swap_first_last((1, 2, 3, 4))
print("Swapped tuple: " result)

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 15


5. The code provided below is intended to search an element from a list. However, there
are syntax and logical errors in the code. Rewrite the code in python after
removing all error(s). Underline each correction done in the code.

def Linear_Search(L)
item=int(input("Enter the value that you want to search: ")
for i in range(len(L)):
if L[i]==item:
print("Element found at index: " i)
break
else:
print("Element not found")
Linear_Search([25,78,45,36,21,10])
6. What possible output(s) are expected to be displayed on screen at the time of
execution of the program from the following code? Also specify the minimum values
that can be assigned to each of the variables BEGIN and LAST.

import random
VALUES = [10, 20, 30, 40, 50, 60, 70, 80]
BEGIN = random.randint (1, 3)
LAST = random.randint(2, 4)
for I in range (BEGIN, LAST+1):
print (VALUES[I], end = "-")

(i) 30-40-50- (ii) 10-20-30-40-


(iii) 30-40-50-60- (iv) 30-40-50-60-70-

7. Identify the correct output(s) of the following code. Also write the minimum and the
maximum possible values of the variable b.
import random
a="Wisdom"
b=random.randint(1,6)
for i in range(0, b, 2):
print(a[i],end='#')

(A) W# (B) W#i# (C) W#s# (D) W#i#s#


8. Look at the following python code and find the possible output(s) from the options (i)
to (iv) following it. Also, write the highest and lowest values that can be pointed by
label VALUE.
import random
for m in range(4):
VALUE = random.randrange(4,11) + m
print(VALUE, "#", end=" ")

a) 6 # 7 # 12 # 13 # b) 5 # 11 # 8 # 11 #
c) 4 # 7 # 12 # 14 # d) 9 # 15 # 8 # 6 #

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 16


9. What possible outputs(s) will be obtained when the following code is executed?
import random
fruit=['banana', 'apple', 'orange', 'grapes']
for k in range(2,0,-1):
R=random.randrange(k)
print(fruit[R], end='*')

a) apple*banana* b) banana*banana*
c) orange*apple* d) apple*apple*
10. How is a mutable object different from an immutable object in Python? Identify one
mutable object and one immutable object from the following: (1,2), [1,2], {1:1,2:2},
‘123’
11. Define Operator Associativity. Write the following operators in descending order of
their operator precedence:
or, **, and, +, *, ==, ()

12. If L1=[1,2,3,2,1,2,4,2, . . . ], and L2=[10,20,30, . . .], then


(Answer using built-in functions only)
i.
A. Write a statement to count the occurrences of 4 in L1.
OR
B. Write a statement to sort the elements of list L1 in ascending order.

ii.
A. Write a statement to insert all the elements of L2 at the end of L1.
OR
B. Write a statement to reverse the elements of list L2.
13. If M1=[10,20,30,……] and M2=[3,6,9,12, …….], then
Write the Python statements for each of the following tasks using BUILT-IN
functions/methods only:
i.
A. To delete an element 20 from the list M1.
OR
B. Write a statement to add an element in M2 between 9 and 12.

ii.
A. Write a statement to sort the elements of list M1 in descending order.
OR
B. Write the statement to delete the last element of list M2.
14. Consider a string message= “Programming develops critical thinking and problem-
solving skills”
Write the Python statements for each of the following tasks using BUILT-IN
functions/methods only:
i.
A. Write a statement to convert the complete string in capital letters.
OR
B. To check whether a string named as message starts with “Th” or not.
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 17
ii.
A. Write a statement to convert the string into a list.
OR
B. Replace the word ‘thinking’ with the word ‘analysis’ in given string.

15. i.
A. What constraint should be applied on a table column so that duplicate values
are not allowed in that column, but NULL is allowed?
OR
B. What constraint should be applied on a table column so that NULL is not
allowed in that column, but duplicate values are allowed.

ii.
A. Write an SQL command to remove the Primary Key constraint from a table,
named MOBILE. M_ID is the primary key of the table.
OR
B. Write an SQL command to make the column M_ID the Primary Key of an
already existing table, named MOBILE.
16. i.
A. Define degree and cardinality of a relation in RDBMS.
OR
B. Define the term keys in DBMS.

ii.
A. Ravish created a database namely BUSINESS. Now he wants to create a
table in it. For this he needs to open the database that he has created. Write
SQL command to open the database that is created by Ravish.
OR
B. Write any two advantages of DBMS.
17. i.
A. Differentiate between count() and count(*) functions in SQL with
appropriate example.
OR
B. Categorize the following commands as DDL and DML: INSERT, UPDATE,
ALTER, DROP
ii.

A. Write an SQL command change a column name from Date_of_Birth to DOB


of date data type in Employee table.
OR
B. Write an SQL command to change a table name from Employee to Emp.
18. i.
A. What is the advantage of using a csv file for permanent storage?
OR
B. Give any one point of difference between a binary file and a csv file.

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 18


ii.
A. What is the difference between CSV file and Text File?
OR
B. Give one advantage of using CSV file over Binary file.
19. List one advantage and one disadvantage of star topology.
OR
Expand the term SMTP. What is the use of SMTP?
20. How is web browser different from web server?
OR
Write difference between 4-G and 5-G Technology.
21. Write two points of difference between XML and HTML.
OR
Why does switch known as smart hub?
22. Define the term bandwidth in networking.
OR
Define the term gateway in computer networking.

23. Expand the following terms: URL, TCP


OR
How is star topology better than bus topology?
24. Write one advantage and one disadvantage of using Fiber Optic Cable.
OR
Write two points of difference between Circuit Switching and Packet switching.
25. Write difference between text file and binary file.
OR
Write difference between seek() and tell( ) methods.

26. Define pickling and unpickling with binary files.


OR
Write any two advantages of data file handling in python.
27. Write any two differences between ‘rb+’ and ‘wb+’ file modes.

28. Define degree and cardinality of a relation in DBMS.

29. Define constraint. Write syntax to add primary key constraint in existing table.

30. Write difference between Equi Join and Natural join.

31. Write difference between DELETE and DROP command.

32. Write difference between WHERE and HAVING clause.

33. Write difference between fetchone( ) and fetchall( ).

34. Define absolute path and relative path.

35. Define pickling and unpickling.

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 19


36. Define stack. Write any two applications of stack.

37. Explain the use of ‘Foreign Key’ in a Relational Database Management System. Give
example to support your answer.

03 MARKS QUESTIONS
1. Write a function LenFourWord(L), where L is the list of elements (list of words)
passed as argument to the function. The function returns another list named
‘indexList’ that stores the indices of all four lettered word of L.
For example:
If L contains [“DINESH”, “RAMESH”, “AMAN”, “SURESH”, “RAVI”]
The output should be:
The indexList will have [2, 4]
2. Write a function Replace_Word(M), where M is the list of elements (list of fruits)
passed as an argument to the function. The function should replace those fruits which
start with any vowel, with the length of the word and display the updated list.
For example:
If list M contains ["mango", "apple", "Avocado", "banana", "orange"]
The output should be:
['mango', 5, 7, 'banana', 6]
3. Write a function Assess_Risk(weight, height, age) to calculate BMI and assess the
risk level of an individual based on their Body Mass Index (BMI) and age. Where
weight in kilograms, height in meters and age in years.
𝑤𝑒𝑖𝑔ℎ𝑡
Calculate BMI as per given formula : ℎ𝑒𝑖𝑔ℎ𝑡 2
The function should calculate the BMI and display the corresponding risk level of an
individual according to the following criteria:

Criteria Risk Level


BMI>30 or age>=60 High Risk
BMI(>=25 but <=30) and Moderate Risk
age (>=40 but <=59)
BMI<25 and age<40 Low Risk

4. Write a user defined function in Python named Puzzle (W,N) which takes the
argument W as an English word and N as an integer and returns the string where
every Nth alphabet of the word W is replaced with an underscore ("_").

For example: if W contains the word "TELEVISION" and N is 3, then the


function should return the string "TE_EV_SI_N". Likewise for the word
"TELEVISION" if N is 4, then the function should return "TEL_VIS_ON".
5. Write a function EvenOdd(L) in python, to add 1 in all odd values and 2 in all even
values of the list L.
Example: If original elements of the list L are:
L= [35, 12, 16, 69, 26]

The modified list will be:


L= [36, 14, 18, 70, 28]

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 20


6. Write a user defined function in python named ShowGrades(S) which takes the
dictionary S as an argument. The dictionary S contains Name : [Eng, Maths,
Science] as key:value pairs. The function displays the corresponding grade obtained
by the students according to the following grading rules:

Average of Eng, Maths, Science Grade


>=90 A
<90 but >=60 B
<60 C

For example: Consider the following dictionary:


S={“Naina”:[92,86,64], “Nagma”:[65,42,43], “Sumit”:[92,90,88]}
The output should be:
Naina – B
Nagma – C
Sumit - A
7. Write a function NEGATIVE_LIST(LST), where LST is the list of elements passed as
argument to the function. The function returns another list named ‘negativelist’ that
stores the negative Elements of LST.
For example:
If LST contains [-21,20,-14,0,11,-33,86]
The negativelist will have - [-21,-14,-33]

8. Write a function SumDiv(L,x), where L is a list of integers and x is an integer; passed


as arguments to the function. The function returns the sum of elements of L which
are divisible by x or x+1.
For example,
If L Contains [10, 27, 12, 20, 22] and x is 5
Then function returns 42 (10+12+20)

9. Write a function Count_UpperWord() that counts number of words which start with
uppercase letter in a text file “Novels.txt”.

Example: If the file content is as follows:


The sun dipped low over the horizon, casting a Golden hue across the
bustling streets of Old Delhi. Anjali walked through the narrow lanes.

The Count_UpperWord() function should display the output as:


The number of words start with uppercase letter are: 5
10. Write a function Show_Words( ) in python to read the content of a text file
“NOTES.TXT” and display those words in capital letters which start with any vowel.
Example, if the file contains:
“Comparing apples to oranges”
Then the function should display the output as:
APPLES
ORANGES

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 21


11. Write a user defined function CountDigits() in python which reads the content of a
text file “MyData.TXT” and counts number of digits present in the text file.
12. Write a user defined function COUNTLINES() in Python to read lines from a text file
‘ESSAY.TXT’ and count the lines which are not starting with any vowel.
Example: If the file content are as follows:
An apple a day keeps the doctor away.
We all pray for everyone’s safety.
always tell the truth.

The COUNTLINES() function should display the output as:


The number of lines not starting with any vowel is / are = 1
13. Write a user defined function in Python named ShowInLines () which reads contents
of a text file named “STORY.TXT” and displays every sentence in a separate line.
Assume that a sentence ends with a full stop (.), a question mark (?), or an
exclamation mark (!).

For example, if the content of file STORY. TXT is as follows:


Our parents told us that we must eat vegetables to be healthy. And it turns
out, our parents were right! So, what else did our parents tell?

Then the function should display the file's content as follows:


Our parents told us that we must eat vegetables to be healthy.
And it turns out, our parents were right!
So, what else did our parents tell?
14. Mr. Ashutosh has written a poem in a text file named as “POEM.TXT”. Now he wants
to count number of lines which start with the character ‘W’ (including uppercase and
lowercase) in the text file “POEM.TXT”.
Help him to write a user defined function CountLineW( ) in python to solve the
problem.
Example: If the “POEM.TXT” contents are as follows:
A tiny ant goes marching by,
With little legs and wings to fly.
Carrying crumbs, oh so small,
Working together, one and all.
The output of the function should be:
No. of lines start with character W are: 2
15. Write a function LINESTARTS_H( ) in python which reads the content of a text file
“News.TXT” and counts number of lines which start with the character ‘H’ or ‘h’ in a
text file.

Example: If the “News.TXT” contents are as follows:


He follows covid protocol.
Stay home stay safe.
His brother wears mask when he
goes to outside.

The output of the function should be:


No. of lines start with character H are: 2
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 22
16. Write a function ETCount() in Python, which should read each character of a text file
“TESTFILE.TXT” and then count and display the count of occurrence of alphabets E
and T individually (including small cases e and t too).
Example:
If the file content is as follows:
Today is a pleasant day.
It might rain today.
It is mentioned on weather sites
The ETCount() function should display the output as:
E or e: 6
T or t : 9
17. Write a function CountYouMe( ) in python which reads the content of a text file
“BIOGRAPHY.TXT” and counts the words ‘You’ and ‘Me’ separately. (Not case
sensitive).
Example:
If the contents in “BIOGRAPHY.TXT” are as follows:

You are a hero for me


you gifted a book to me which helped me
a lot to learn the programming
It gave me a chance to develop business software
The output of the function should be:
Count of You in file: 2
Count of Me in file: 4

18. Write a function CountDigits( ) in python which reads the content of a text file
“MyData.TXT” and counts number of digits present in the text file.

Example:
If the contents in “MyData.TXT” are as follows:
In 2023 we 22 students will appear in exam for 5 subjects

The output of the function should be:


No. of digits are: 7

19. Predict the output of the following code:


d = {"tea": 15, "sugar": 7, "milk": 9}
str1 = ""
for key in d:
str1 = str1 + str(key) + "#"
str2 = str1[-3:-9:-1]
print(str2)
OR
Write output for the following python code:
tuple1 = (11, 22, 33, 44, 55 ,66)
list1 =list(tuple1)
new_list = [ ]

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 23


for i in list1:
if i%2==0:
new_list.append(i)
new_tuple = tuple(new_list)
print(new_tuple)
20. Predict the output of the Python code given below:

def Diff(N1,N2):
if N1>N2:
return N1-N2
else:
return N2-N1
NUM= [10,23,14,54,32]
for CNT in range (4,0,-1):
A=NUM[CNT]
B=NUM[CNT-1]
print(Diff(A,B),'#', end=' ')

OR
Predict the output of the Python code given below:
tuple1 = (11, 22, 33, 44, 55 ,66)
list1 =list(tuple1)
new_list = []
for i in list1:
if i%2==0:
new_list.append(i)
new_tuple = tuple(new_list)
print(new_tuple)

21. Write output for the following python code:

def ChangeString(s):
m="" #empty string
for i in range(0,len(s)):
if(s[i].isupper()):
m=m+s[i].lower()
elif s[i].islower():
m=s[i].upper()+m
else:
if i%2==0:
m=m+s[i-1]
else:
m="%"+m
print(m)
ChangeString('Try2Solve@')
OR
Predict the output of the Python code given below:
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 24
p=4
def CheckData(y):
global p
print(p+2)
r=y
p=r+8
print(p)
CheckData(12)
print(p)

22. Write the output of the code given below:


def FindOutput(p, q=4, r=75):
x=p**2*4
y=x+r
print(x, "@", y)
return y

c=FindOutput(q=5,r=7,p=4)
a,b=10,12
c=FindOutput(b,a,c)
print(a,"@",b,"@",c)
OR
What will be the output of the following code:
def Value2New(M, N=10):
M=M+N
N = N*2
if N%10==0:
N=N/5
return(M,N)
P,Q = Value2New(100,20)
print(P,’#’,Q)
P,Q = Value2New(50)
print(P,’#’,Q)

23. Write the output of the code given below:


p=5
def sum(q,r=2):
global p
p=r+q**2
print(p, end= '#')
a=10
b=5
sum(a,b)
sum(r=5,q=1)
OR

Write the output of the Code given below:


By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 25
def Timing(T, m=0):
print(“Present Time is”,end=’:’)
if m>10 and m<=20:
print(“Quarter Past”,T)
elif m<=40:
print(“Half Past”,T)
elif m<=59:
print(“Quarter to”,T+1)
else:
print(“Incorrect Minutes”)
Timing(5,18)
Timing(11)
Timing(12,60)

24. Write output of the code given below:


k=4
def DataWork(a, b=5):
global k
k=b+a**2
print(k, end="@")
p=10
q=15
DataWork(p,q)
DataWork(b=3, a=8)
OR
Write the output of the code given below:
a =30
def call (x) :
global a
if a%2==0:
x+=a
x=5
else:
x-=a
return x
print(call(35),end="#")
print(call(40),end= "@")

25. Predict the output of the following code


s="science"
L=[1,3,4,8,7]
d={ }
for i in range(len(L)):
if i%2==0:
d[L.pop()]=s[i]
else:
d[L.pop()]=i*2
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 26
for k,v in d.items():
print(k,v,sep="-")

OR
Predict the output of the following code:
def convert(p,q=10):
p=p/q
q=p%q
return p
a=150
b=5
a=convert(a,b)
print(a,b,sep="#")
b=convert(b)
print(a,b,sep="$")
26. Predict the output of the code given below :
def makenew(mystr):
newstr= “” #empty string
count=0
for i in mystr:
if count%2!=0:
newstr=newstr+str(count)
else:
if i.islower():
newstr=newstr+i.upper()
else:
newstr=newstr+i
count+=1
print(newstr)
makenew ( "Car@6")

27. A.
Consider a dictionary named Books which contains name of books as key and price
as value.
Write the following user defined functions in python and perform the specified
operations on a stack named Book_Name.
i. Push_BName() : It checks price of the book from the dictionary Books and
pushes name of such books which have price more than 350 rupees, into the
stack, Book_Name.
ii. Pop_BName(): It deletes the name of books from stack Book_Name and
displays them. The function should also display “Stack is Empty” message when
there is no more book left in the stack.

For example: If the dictionary Books contains the following data:


Books={“Physics”:550,“Maths”:300,“Chem”:480,“Hindi”:250,“CS”:360, “English”
:310}

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 27


After execution of Push_BName(), the stack Book_Name should have:
[“Physics”,“Chem”,“CS”]

And on execution of Pop_BName(), the following output should be displayed:


CS
Chem
Physics
Stack is Empty
OR
B.
Neelam has a list containing 10 integers. You need to help her to create a program
with separate user defined functions to perform the following operations based on this
list.

i. Traverse the content of the list and push the even numbers into a stack.

ii. 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 stack should be:


38 22 98 56 34 12

28. You have a stack named MovieStack that contains records of movies. Each movie
record is represented as a list containing movie_title, director_name, and
release_year.
Write the following user-defined functions in Python to perform the specified
operations on the stack MovieStack:
i. add_movie(MovieStack, new_movie): This function takes the stack MovieStack
and a new movie record new_movie as arguments and pushes the new movie
record onto the stack and display the stack.
ii. remove_movie(MovieStack): This function removes the topmost movie record
from the stack and returns it. If the stack is already empty, the function should
display "Underflow".
iii. view_top(MovieStack): This function displays the topmost element of the stack
without deleting it. If the stack is empty, the function should display 'None'.
OR
Stationery_Item is a dictionary containing the details of stationary items.
Write a user defined function PUSH_DATA(Stationery_Item), to push the name of
those items into the stack named as PriceStack which have price more than 75 and
display stack. Also display the number of elements pushed into the stack.
For example: If the dictionary contains the following data:
Stationery_Item={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25}
The stack should contain
['Pen', 'Notebook']
The output should be:
Number of elements in stack: 2

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 28


29. A.
Ms. Aarti has a stack named ToysStack that contains records of toys. Each toy record
is represented as a list containing toy_name, brand_name and year_of_manufacture.
You as a python programmer help her to write the following user-defined functions in
Python to perform the specified operations on the stack ToysStack:
i. PUSH_TOY(ToysStack, new_toy): This function takes the stack ToysStack and
a new toy record new_toy as arguments and pushes the new toy record onto
the stack.
ii. POP_TOY(ToysStack): This function pops the topmost toy record from the stack
and returns it. If the stack is already empty, the function should display
"Underflow".
iii. PEAK(ToysStack): This function displays the topmost element of the stack
without deleting it. If the stack is empty, the function should display 'None'.
OR
B.
Consider a list named Space which contains the terms related to space.
Write the following user defined functions in python and perform the specified
operations on a stack named MyStack.
i. Push_Term(): It checks every term from the list Space and pushes all such
terms which have 5 or more characters into the stack, MyStack.
ii. Pop_Term(): It pops the terms from stack, MyStack and displays them. The
function should also display “Stack is Empty” when there are no more
elements left in the stack.

30. Consider a list named Space which contains the terms related to space.
Write the following user defined functions in python and perform the specified
operations on a stack named MyStack.
i. Push_Term(): It checks every term from the list Space and pushes all such
terms which have 5 or more characters into the stack, MyStack.
ii. Pop_Term(): It pops the terms from stack, MyStack and displays them. The
function should also display “Stack is Empty” when there are no more
elements left in the stack.

For Example: If the list Space contains the following data:


Space=["Asteroid","Comet","Cosmos","Galaxy","Crater"]
Then on execution of Push_Term(), the stack MyStack should store:
['Asteroid', 'Cosmos', 'Galaxy', 'Crater']
and on execution of Pop_Term(), the following output should be displayed:
Crater
Galaxy
Cosmos
Asteroid
Stack is empty

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 29


31. A.
Write a function in Python, Push(SItem) where , SItem is a dictionary containing the
details of stationary items– {Sname:price}.
The function should push the names of those items in the stack who have price
greater than 75. Also display the count of elements pushed into the stack.
For example:
If the dictionary contains the following data:
Ditem={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25}
The stack should contain
Notebook
Pen
The output should be:
The count of elements in the stack is 2

OR
B.
Write the definition of a user-defined function `push_even(N)` which accepts a list of
integers in a parameter `N` and pushes all those integers which are even from the
list `N` into a Stack named `EvenNumbers`.
i. Write function pop_even() to pop the topmost number from the stack and
returns it. If the stack is already empty, the function should display "Empty".
ii. Write function Disp_even() to display all element of the stack without deleting
them. If the stack is empty, the function should display 'None'.
For example:
If the integers input into the list `VALUES` are: [10, 5, 8, 3, 12] Then
the stack `EvenNumbers` should store: [10, 8, 12]

32. A.

Ravina has created a list of integer elements. Create user defined functions to
perform the following operations:

i. Create a function Push_Number(L) which will insert the number into the stack
which is divisible by 5.

ii. Define a function Pop_Number( ) from the stack and display the value of TOP
after deletion of the element.

For Example: If the sample Content of the list is as follows:


P=[38,45,42,78,65,60,17,44,20,36]
Sample stack should be:
20 60 65 45
OR
B.
Arun has created a dictionary containing employee name and their salary as key value
pair of 05 employees. Create user defined functions to perform the following
operations:

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 30


i. Push the keys (name of employee) of dictionary into the stack where the
corresponding value (salary) is more than 20000.

ii. Delete the element from the stack and display the stack after deletion of the
element.

04 MARKS QUESTIONS
1. Consider the table ORDERS as given below:
O_Id C_Name Product Quantity Amount
1001 Jitendra Laptop NULL 12000
1002 Mustafa Smartphone 2 10000
1003 Dhwani Headphone 1 1500
1008 Sonali Laptop 3 40000
1025 Jayra Headphone NULL 22000
1231 Varun Laptop 5 90000

A) Write the following queries:


i. To display the total Quantity for each Product, excluding Products with total
Quantity less than 5.
ii. To display the orders table sorted by total amount in descending order.
iii. To display the distinct customer names from the Orders table.
iv. Display the sum of amount of all the orders for which the quantity is null.
OR
B) Write the output:
i. Select c_name, sum(quantity) as total_quantity from orders group by
c_name;
ii. Select * from orders where product like '%phone%';
iii. Select o_id, c_name, product, quantity, price from orders where price
between 1500 and 12000;
iv. Select max(price) from orders;
2. Consider a table TRAIN as given below:

TNo TName Train_Type Source Destination Fare


12001 Rajdhani Express Superfast Delhi Mumbai 3000
12625 Shatabdi Express Superfast Delhi NULL 1200
12501 North East Express Express Guwahati Delhi 1500
16159 Kanyakumari Exp Express Kanyakumari Delhi 2500
20814 Jodhpur-Puri Exp Express Jodhpur Puri 2800
19412 Sabarmati Express Express Sabarmati NULL 1100

A) Write the following queries:


i. Display type of train and total fare of each type of train.
ii. Display Train Number, Train Name and Fare of those trains whose name
starts with the alphabet letter ‘S’.
iii. Display train number, train name and source of those trains whose
destination is NULL.
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 31
iv. Count the number of trains which have train type as superfast and source is
‘Delhi’.
OR
B) Write the output:
i. Select TNAME, Fare from TRAIN Where Fare<2000 order by TName;
ii. Select avg(fare) from TRAIN group by Train_Type;
iii. Select TName, Destination, Fare from TRAIN where fare <>2500 and
destination IS NULL;
iv. Select min(fare) from TRAIN where Train_Type= “Express”;
3. Navdeep creates a table RESULT with a set of records to maintain the marks secured
by students in Sem 1, Sem2, Sem3 and their division. After creation of the table,
he has entered data of 7 students in the table.

ROLL_NO SNAME SEM1 SEM2 SEM3 DIVISION


101 Rahul 366 410 402 I
102 Ishika 300 350 325 I
103 Suman 400 410 415 I
104 Shankar 350 357 415 I
105 Rajesh 100 75 178 IV
106 Sudha 100 205 217 II
107 Anita 470 450 471 I

Write the SQL queries:


i. Insert the following record into the table :
Roll No- 108, Name- Aadit, Sem1- 470, Sem2-444, Sem3-475, Div – I.
ii. Increase the SEM2 marks of the students by 3% whose name begins with
‘N’.
iii. Delete the record of students securing IV division.
iv. Add a column REMARKS in the table with datatype as varchar with 50
characters.
OR
Write the output of the queries (i) to (iv), based on the table given table:

TABLE: ELECTRONICS
Item_ID IName Manufacturing_Date Make Qty Price

IT026 Refrigerator 2019-12-15 Samsung 15 16000

IT039 TV 2020-06-25 Samsung 7 28000

IT088 Computer 2020-01-30 Acer 15 44000

IT054 TV 2022-02-16 Sony 10 15000

IT061 Computer 2021-11-17 IFB 12 21000

i. Select COUNT(*), Make From Electronics Group by Make Having


COUNT(*)>1;

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 32


ii. Select Max(Manufacturing_Date), Min(Price) From Electronics;
iii. Select Item_ID, IName From Electronics Where IName like “%sh%”;
iv. Select Avg(Price) From Electronics Where Qty > 10;
4. A librarian is considering to maintain the inventory of books using SQL.

Table: BOOKS

Book_No BookName Price Quantity

504 Indian History 245.50 10

685 Journey of Village 168.50 05

847 Evolution of Computer 350.00 15

321 Inside the Earth 425.00 10

456 Indian Farmer 200.00 08

259 My Village My Country 200.00 05

Write SQL queries:


i. Insert the following data into the attributes Book_No, BookName and Price
respectively in the given table BOOKS. BOOK_No = 777, BookName = “Poet
of India” and Price = 225.00
ii. Increase the price of books by 5% whose book name begins with letter ‘I’.
iii. Delete the records of those books whose quantity is more than 7.
iv. Add a column AUTHOR in the table with data type is varchar with 40
characters.
OR
Write outputs of the SQL queries (i) to (iv) based on the relation PLAYER given
below:

TABLE: PLAYER
Pcode Pname Gender DOB State Game Age
401 Ravita F 2000-10-09 Punjab Cricket 22
402 Gauravi F 2001-01-22 Bihar Football 21
403 Rakesh M 2000-11-29 Haryana Hockey 22
404 Divya F 2002-05-12 Rajasthan Hockey 20
405 Hemali F 2000-09-21 Gujarat Cricket 22
406 Ashok M 2000-12-12 Rajasthan Hockey 21

i. SELECT Game, Count(*) FROM PLAYER GROUP BY Game;


ii. SELECT Max(DOB), MIN(Age) FROM PLAYER;
iii. SELECT Pname, State FROM PLAYER WHERE State like “%a_”;
iv. SELECT Gender, AVG(Age) FROM PLAYER GROUP BY Gender;

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 33


5. Mayanti just started to work for a sports academy having several branches across
India. The sports academy appoints various trainers to train various sports. She has
been given the task to maintain the data of the trainers. She has made a table called
TRAINER in the database which has following records:
Table: TRAINER
TrainerNo Name City HireDate Salary
101 SUNAINA MUMBAI 1998-10-15 90000
102 ANAMIKA DELHI 1994-12-24 80000
103 DEEPTI CHANDIGARH 2001-12-21 82000
104 MEENAKSHI DELHI 2002-12-25 78000
105 RICHA MUMBAI 1996-01-12 95000
106 MANIPRABHA CHENNAI 2001-12-12 69000

Write SQL Queries:


i. Insert a new record in table TRAINER with values, TrainerNo = 107, Name =
Swastik, HireDate = 1999-01-22, Salary = 90000.
ii. Increase the salary of those Trainer having city as DELHI by 5000.
iii. Remove those records from table TRAINER who were hired after year 2000.
iv. Add a new column Grade with datatype as Varchar and maximum size as 2.
OR
Consider the following tables and answer the questions (i) to (iv):

Table: Garment
GCode GName Rate Qty CCode
G101 Saree 1250 100 C03
G102 Lehanga 2000 100 C02
G103 Plazzo 750 105 C02
G104 Suit 2000 250 C01
G105 Patiala 1850 105 C01

Table: Cloth
CCode CName
C01 Polyester
C02 Cotton
C03 Silk
C04 Cotton-Polyester

What will be the output of following SQL commands?


i. SELECT DISTINCT QTY FROM GARMENT;
ii. SELECT SUM(QTY) FROM GARMENT GROUP BY CCODE HAVING COUNT(*)>1;
iii. SELECT GNAME, CNAME, RATE FROM GARMENT G,CLOTH C WHERE G.CCODE
= C.CCODE AND QTY>100;
iv. SELECT AVG(RATE) FROM GARMENT WHERE RATE BETWEEN 1000 AND 2000;

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 34


6. Write the output of the queries (i) to (iv) based on the table:

TABLE: EMPLOYEE
EMPNO NAME DATE_OF_ JOINING SALARY CITY
5001 SUMIT SINGH 2012-05-24 55000 JAIPUR
5002 ASHOK SHARMA 2015-10-25 65000 DELHI
5003 VIJAY SINGH 2009-09-09 85000 JAIPUR
5004 RAKESH VERMA 2020-12-21 60000 AGRA
5006 RAMESH KUMAR 2011-01-22 72000 DELHI

i. SELECT AVG(SALARY) FROM EMPLOYEE WHERE CITY LIKE “%R”;


ii. SELECT COUNT(*) FROM EMPLOYEE WHERE DATE_OF_JOINING BETWEEN
“2011-01-01” AND “2020-12-21”;
iii. SELECT DISTINCT CITY FROM EMPLOYEE WHERE SALARY >65000;
iv. SELECT CITY, SUM(SALARY) FROM EMPLOYEE GROUP BY CITY;

7. Consider the following table named as EMPLOYEE.


Table : EMPLOYEE
ENO NAME Salary DOB GENDER DEPT
1001 Ankit 25000 1992-09-01 Male HR
1002 Saloni 60000 1991-12-15 Female R&D
1003 Sanjay 40000 1988-09-04 Male HR
1007 Harish 42000 1985-10-19 Male Production
1004 Sunita 30000 1987-11-14 Female Production
1005 Ashok 25000 1988-03-31 Male HR
1006 Namita 50000 1986-06-23 Female Production

Write output of the following queries (i) to (iv):


i. SELECT COUNT(*) FROM EMPLOYEE
GROUP BY DEPT HAVING COUNT(*)>1;

ii. SELECT DISTINCT DEPT FROM EMPLOYEE;

iii. SELECT MAX(DOB), MIN (DOB) FROM EMPLOYEE;

iv. SELECT NAME, SALARY, DEPT FROM EMPLOYEE ORDER BY NAME;

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 35


8. Write outputs of the SQL queries (i) to (iv) based on the relations PLAYER and GAME
given below:
TABLE: PLAYER
Pcode Pname Gender DOB State Gcode
205 Sunil M 2000-10-09 Assam 03
202 Akash M 2001-01-22 Kerala 02
209 Diksha F 2000-11-29 Manipur 01
211 Mamta F 2002-05-12 Kerala 02
208 Sudha F 2000-09-21 Rajasthan 01
207 Ravi M 2000-12-12 Assam 03

TABLE: GAME
Gcode Gname no_of_players Gtype
01 Tennis 1 Outdoor
02 Cricket 11 Outdoor
03 Badminton 1 Indoor

Write output of the following queries (i) to (iv):


i. SELECT Pname, Gname FROM PLAYER P, GAME G WHERE P.Gcode=G.Gcode
ORDER BY Pname;
ii. SELECT Gender, Count(*) FROM PLAYER GROUP BY Gender;
iii. SELECT P.Pname, P.State, G.Gname FROM PLAYER P, GAME G WHERE
P.Gcode=G.Gcode and Gender= “F”;
iv. SELECT Pname, Gname, State FROM PLAYER P, GAME G WHERE
P.Gcode=G.Gcode and State like “%a_”;
9. Consider the following table named as VEHICLE :
Vehicle_ID Make Model Year Colour Price
V01 Maruti Suzuki Swift 2020 Red 750000
V02 Hyundai Creta 2021 White 1650000
V03 Tata Nexon 2022 Blue 1200000
V04 Honda City 2019 Silver 1350000
V05 Mahindra XUV300 2020 Black 1250000
V06 Kia Seltos 2021 Yellow 1800000
V17 Hyundai Venue 2018 Orange 900000
V08 Renault Kwid 2022 Green 500000
V09 Hyundai Creta 2022 Black 1850000
V11 BMW X1 2021 Blue 4500000

i. Write degree and cardinality of given table Vehicle.


ii. Write SQL command to show description of the table Vehicle.
iii. Identify the most appropriate attribute, which can be considered as Primary
key. Justify your answer.

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 36


iv. If two columns are added and 2 rows are deleted from the table VEHICLE,
what will be the new degree and cardinality of the above table?
10. A csv file "Happiness.csv" contains the data of a survey. Each record of the file
contains the following data:
● 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.
11. Ms. Ragini is a python programmer working in a hardware store. She has to develop
a simple inventory management system of different kind of parts of vehicles. She
has created a csv file named parts.csv, to store the details. The structure of
parts.csv is:
[P_ID, P_Name, Make, Price]
Where
P_ID is part ID (integer)
P_Name is Name of Part (string)
Make is name of brand (string)
Price is the price of part (float)

Ms. Ragini wants to write the following user defined functions in python:
i. Save_Data( ) : To accept details of equipment/parts from the user and add
it to a csv file “parts.csv”.
ii. Delete_Data( ) : To accept a part ID from user and removes the record of
a part from the file “parts.csv” with given part ID. If part ID not found then
it should display a relevant message “Part ID is not found”. Before removing
the record of a part, it should display name of part.

12. Mr. Ankit is a python programmer working in a software company. He has to develop
a simple inventory management system of all employees working in an educational
institute. He has created a csv file named record.csv, to store the details of
employees. The structure of record.csv is:
[employee_id, emp_name, salary]
Mr. Ankit wants to write a Program in Python that defines and calls the following
user defined functions:
i. ADD() – To accept and add data of 6 employees to a CSV file ‘record.csv’.
ii. COUNTR() – To count the number of records present in the CSV file named
‘record.csv’.

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 37


13. Ms. Mamta is a python programmer dealing with a furniture business. She has to
develop a simple inventory management system of all furniture data of her
business. She has created a csv file named furdata.csv, to store the details of
furniture. The structure of furdata.csv is:
[F_ID, FNAME, FPRICE]

Ms. Mamta wants to write a Program in Python that defines and calls the following
user defined functions:
i. add() – To accept and add data of a furniture to a CSV file ‘furdata.csv’.
ii. search()- To display the records of the furniture which has price more than
10000.

14. Write a program in Python that defines and calls the following functions:

i. Insert() – To accept details of clock from the user and stores it in a csv file
‘watch.csv’. Each record of clock contains following fields – ClockID,
ClockName, YearofManf, Price. Function takes details of all clocks and stores
them in file in one go.

ii. Delete() – To accept a ClockID and removes the record with given ClockID
from the file ‘watch.csv’. If ClockID not found then it should show a relevant
message. Before removing the record it should print the record getting
removed.
15. Write a program in Python that defines and calls the following functions:

i. saving() – To accepts details of equipments from the user in following format


(ID, Name, Make, Price) and save it in a csv file ‘parts.csv’. Function saves
one record at a time.

ii. search() – To accept two prices and displays details of those equipments
which has price between these two values.

16. Aman has been entrusted with the management of Law University Database. He
needs to access some information from FACULTY and COURSES tables for a survey
analysis. Help him extract the following information by writing the desired SQL
queries as mentioned below.

Table: FACULTY
F_ID FName LName Hire_Date Salary
102 Amit Mishra 12-10-1998 12000
103 Nitin Vyas 24-12-1994 8000
104 Rakshit Soni 18-5-2001 14000
105 Rashmi Malhotra 11-9-2004 11000
106 Sulekha Srivastava 5-6-2006 10000

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 38


Table: COURSES
C_ID F_ID CName Fees
C21 102 Grid Computing 40000
C22 106 System Design 16000
C23 104 Computer Security 8000
C24 106 Human Biology 15000
C25 102 Computer Network 20000
C26 105 Visual Basic 6000

i. To display complete details (from both the tables) of those Faculties whose
salary is less than 12000.
ii. To display the details of courses whose fees is in the range of 20000 to 50000
(both values included).
iii. To increase the fees of all courses by 500 which have "Computer" in their
Course names.
iv. (A) To display names (FName and LName) of faculty taking System Design.
OR
(B) To display the Cartesian Product of these two tables.
17. Ms. Nishi has been entrusted with the bank Database. She needs to access some
information from LOAN and BORROWER tables for a survey analysis. Help her to extract
the following information by writing the desired SQL queries as mentioned below.
Table: LOAN
loan_number branch_name Amount
L123 Nagpur 45000
L456 Pune 60000
L347 Delhi 80000
L987 Delhi 25000
L901 Pune 45000

Table : BORROWER
customer_name loan_number
Ajit Das L456
Rohan Yadav L901
Suman Verma L123
Ayesha Tiwari L987
Saurav L347

i. To display customer name and branch name of those customers who have
taken loan from Delhi branch.
ii. To display loan number, customer name and amount of those customers who
have taken loan more than 40000.
iii. To display branch name and average amount of that branch which has given
average loan amount more than 50000.
iv.
A. To display customer name and amount in descending order of amount.
OR

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 39


What will be degree of resultant table after performing natural join of these
two tables.
18. A table, named STATIONERY, in ITEMDB database, has the following structure:

Field Type
itemNo int(11)
itemName varchar(15)
price float
qty int(11)

Write the following Python function to perform the specified operation:


AddAndDisplay( ) : To input details of an item and store it in the table
STATIONERY. The function should then retrieve and display all records from the
STATIONERY table where the Price is greater than 120.
Assume the following for Python-Database connectivity:
Host: localhost, User: root, Password: Pencil
19. Alok wants to create a table named BOOK in the LIBRARY database, which should
have the following structure:

Field Type Remarks


Book_ID int Primary Key
BName varchar(25) NOT NULL
Quantity int
Price float(6,2)
Author Varchar (20)
Write the following Python function to perform the specified operation:
• Create_and_ADD() : To create a table BOOK as per details given above and after
creating table, insert the following record in the table BOOK.
Book_ID:12, BName:“Godaan”, Quantity:15,Price:210,Author:“Premchand”
Assume the following for Python-Database connectivity:
host: localhost, user: root, password: program
20. The code given below inserts the following record in the table Student:
RollNo – integer
Name – string
Clas – integer
Marks – integer
Note the following to establish connectivity between Python and MYSQL:
● Username is root
● Password is tiger
● The table exists in a MYSQL database named school.
● The details (RollNo, Name, Clas and Marks) are to be accepted from the user.
Write the following missing statements to complete the code:
Statement 1 – to form the cursor object
Statement 2 – to execute the command that inserts the record in the table Student.
Statement 3- to add the record permanently in the database

import mysql.connector as mysql


def sql_data():
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 40
con1=mysql.connect(host="localhost",user="root",password="tiger",database
="school")
mycursor=_________________ #Statement 1
rno=int(input("Enter Roll Number :: "))
name=input("Enter name :: ")
clas=int(input("Enter class :: "))
marks=int(input("Enter Marks :: "))
querry="insert into student values({}, '{}', {}, {})".format (rno, name, clas,
marks)
______________________ #Statement 2
______________________ # Statement 3
print("Data Added successfully")

21. The code given below reads the following record from the table named student and
displays only those records who have marks greater than 75:
RollNo – integer
Name – string
Clas – integer
Marks – integer
Note the following to establish connectivity between Python and MYSQL:

● Username is root
● Password is tiger
● The table exists in a MYSQL database named school.
Write the following missing statements to complete the code:
Statement 1 – to form the cursor object
Statement 2 – to execute the query that extracts records of those students whose
marks are greater than 75.
Statement 3- to read the complete result of the query (records whose
marks are greater than 75) into the object named data, from the table student in
the database.

import mysql.connector as mysql


def sql_data():
con1=mysql.connect(host="localhost",user="root",password="tiger",
database="school")
mycursor=_______________ #Statement 1
print("Students with marks greater than 75 are : ")
_________________________ #Statement 2
data=__________________ #Statement 3
for i in data:
print(i)
print()

22. The code given below inserts the following record in the table Employee:
Emp_id – integer
Ename – string
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 41
Date_of_Birth – date
Salary – float
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is computer
The table exists in a MYSQL database named Employee.
The details (Emp_id, Ename, Date_of_Birth, Salary) are to be accepted from the
user.
Write the following missing statements to complete the code:
i. Statement 1 – to form the cursor object
ii. Statement 2 – to execute the command that inserts the record in the table
Employee.
iii. Statement 3- to add the record permanently in the database

import mysql.connector as mycon


def AddRecord():
mydb=mycon.connect(host="localhost",user="root", password=
"computer", database="bank")
mycursor= ________________ #Statement 1
Emp_id=int(input("Enter Employee Id: "))
Ename=input("Enter Employee Name : ")
dob=input("Enter Date of Birth : ")
salary=float(input("Enter Salary : "))
qry="insert into Employee values ({},'{}','{}',{})".format (Emp_id,
Ename, dob, salary)
_________________ #Statement 2
_________________ # Statement 3
print("Data Added successfully")

23. The code given below extract and display the following record from the table
Employee.
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is computer
The table exists in a MYSQL database named Employee.
The details (Emp_id, Ename, Date_of_Birth, Salary) are present in table.
Write the following missing statements to complete the code:
i. Statement 1 – to form the cursor object
ii. Statement 2 – to retrieve all records from result set object as per query.
iii. Statement 3 - sequence object in the loop to display the records

import mysql.connector as mycon


def ShowRecord():
mydb=mycon.connect(host="localhost", user="root", password=
"computer", database="bank")
mycursor= __________________ #Statement 1
qry="select * from employee where salary>30000"
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 42
mycursor.execute(qry)
result=mycursor.____________ #Statement 2
for record in ____________ : #Statement 3
print(record)

05 MARKS QUESTIONS
1. Surya is a manager working in a recruitment agency. He needs to manage the
records of various candidates. For this, he wants the following information of each
candidate to be stored: -
- Candidate_ID – integer
- Candidate_Name – string
- Designation – string
- Experience – float
You, as a programmer of the company, have been assigned to do this job for Surya.
i. Write a function to input the data of a candidate and append it in a binary file.
ii. Write a function to update the data of candidates whose experience is more
than 10 years and change their designation to "Senior Manager".
iii. Write a function to read the data from the binary file and display the data of
all those candidates who are not "Senior Manager".
2. Mr. Mohit is working on a school project to manage student records using Python.
The student data is stored in a binary file named STUDENT.DAT. The binary file
STUDENT.DAT contains each record in given format:
{“Admn_No”:admn, “SName”:name, “Marks”:marks}
Where
● Admn_No: Admission Number (integer)
● SName: Student Name (string)
● Marks: Marks (integer)
You as a programmer, help him to write following python functions:
i. ADD_Data() : To write 7 records in binary file STUDENT.DAT by taking the
values for each record from user.
ii. Display_Data() : Read all records from binary file and display them.
iii. Modify_Marks() that updates the marks of a student in the file
STUDENT.DAT based on the admission number provided by the user. If the
admission number does not exist in the file, display an appropriate message.
3. “XYZ Travels Pvt. Ltd.” is a tour and travel management company that maintains the
data of various buses. To store data of buses the company uses a binary file named
“BUS.DAT”. The file contains records in the given format:

[Bus_Number, Starting_Point, Destination]

You as a programmer, help them to write following user defined python functions:
i. Write_Record() : Write n numbers of records in binary file by taking values
for each record from the user.
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 43
ii. Show_Data() : Read all records from binary file and display them.
iii. Write a user defined function Search_Bus() in python to search and display
details of those buses, which have "Ajmer" as destination from the binary file
"BUS.DAT". If no bus has the destination as “Ajmer” in the file, display an
appropriate message.

4. “TechMart Pvt Ltd.” is a retail company specializing in electronics and home


appliances. They maintain a product inventory in a binary file named
“PRODUCT.DAT”, which includes details about each product. The file contains each
record in the following structure:
{“pno”:PNo, “pname”:Pname, “brand”:Brand, “price”:Price}
“TechMart Pvt Ltd.” is currently evaluating the performance of different brands
within their inventory. To assist in generating brand performance reports, they
need a function to count the number of products from a specific brand stored in
the PRODUCT.DAT file.
You as a programmer, help them to write a function CountRecord(Brand) in
Python which accepts the brand name as parameter and count and return number
of products of the given brand which are stored in the binary file “PRODUCT.dat”.

5. “EduTech Solutions” is an educational technology company that provides


academic performance tracking tools for schools and educational institutions. The
company stores student records in a binary file named “STUDENT.DAT”. The
binary file contains each record in given format:
{“Admn_No”:admn, “SName”:name, “Marks”:marks}
“EduTech Solutions” wants to generate a report to highlight high-performing
students. Specifically, they need to identify and display the names of students
who have scored between 80 and 95 marks, inclusive.
You as a programmer, help them to write a function Display_Record() in Python
to display the name of those students who have scored marks between 80 and
95 (including both values).

6. “Sporting Legends Pvt Ltd” is a sports management company that maintains a


digital database of players in various sports. The company uses a binary file
named “PLAYER.DAT” to store player information efficiently. The file contains
records in the given format:
{player_id : [pname, age]}
To comply with updated company policies, “Sporting Legends Pvt Ltd” needs to
revise their player database by removing records of players who are older than
18 years. Help them by writing a function, Delete_Record() that deletes records
of those players whose age is more than 18 years from the file “PLAYER.DAT”.

7. “MelodyMasters Inc.” is a digital music streaming service that maintains a large


database of song records. Each song record is stored in a binary file named
“SONG.DAT”. The file “SONG.DAT” containing records in the given format:
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 44
{song_id : [song_name, singer, release_year]}
The company is in the process of updating its catalogue to reflect that some songs
are being promoted in the year 2020. This requires updating the release_year of
specific songs in the SONG.DAT file to 2020. Write a function, Modify_Song(s_id)
which accepts the song id as a parameter and update the release year of that
song to 2020.

8. “ABHA Technologies” is a data management firm that maintains a digital records


system for storing personal information. The company uses binary files for
efficient storage and retrieval of records. One of their key files is “PEOPLE.DAT”,
in which they want to add personal details of individuals in the following
structure:
[Adhaar_number, Name, Gender, Age]
Write a user defined function Add_Record( ), to add n numbers of records in
binary file “PEOPLE.DAT”.

9. “Topper Books Inc.” is a retail company that manages a large inventory of books
through a digital inventory management system. The company maintains
detailed records of its book inventory in binary file named as “BOOK.DAT” for
efficient storage and retrieval. Each record in binary file “BOOK.DAT” has the
following structure:
[BNo, BName, Qty, Price]
The company's marketing team has decided to run a promotion focusing on high-
value books. To facilitate this promotion, the team needs to extract records of all
books priced above Rs. 400 from the existing binary file BOOK.DAT and save
them into a new file named NEWBOOK.DAT.
You as a programmer, help them to write a user defined function Copy_Book( ),
that copies records of all books whose price is more than 400 from “BOOK.DAT”
to “NEWBOOK.DAT”.
10. A binary file “PEOPLE.DAT” has the following structure:
[Adhaar_number, Name, Gender, Age]

i. Write a user defined function ModifyData( ) by taking adhaar number of a


person from user and update name of a person in binary file PEOPLE.DAT.

ii. Write a function Show_Record( ) in Python that would read contents of the file
“PEOPLE.DAT” and display the details of those people whose age is above 45.
11. Event Horizon Enterprises is an event planning organization. It is planning to set up
its India campus in Mumbai with its head office in Delhi. The Mumbai campus will
have four blocks/buildings - ADMIN, FOOD, MEDIA, DECORATORS. You, as a network
expert, need to suggest the best network-related solutions for them to resolve the
issues/problems mentioned in points (I) to (V), keeping in mind the distances
between various blocks/buildings and other given parameters.

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 45


i. Suggest the most appropriate location of the server inside the MUMBAI
campus. Justify your choice.
ii. Which hardware device will you suggest to connect all the computers within
each building?
iii. Draw the cable layout to efficiently connect various buildings within the
MUMBAI campus. Which cable would you suggest for the most efficient data
transfer over the network?
iv. Is there a requirement of a repeater in the given cable layout? Why/ Why not?
v.
A. What would be your recommendation for enabling live visual
communication between the Admin Office at the Mumbai campus and
the DELHI Head Office from the following options:
a) Video Conferencing b) Email
c) Telephony d) Instant Messaging
OR

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 46


B. What type of network (PAN, LAN, MAN, or WAN) will be set up among
the computers connected in the MUMBAI campus?
12. MakeInIndia Corporation, an Uttarakhand based IT training company, is planning to
set up training centres in various cities in next 2 years. Their first campus is coming
up in Kashipur district. At Kashipur campus, they are planning to have 3 different
blocks for App development, Web designing and Movie editing. Each block has
number of computers, which are required to be connected in a network for
communication, data and resource sharing. As a network consultant of this company,
you have to suggest the best network related solutions for them for issues/problems
raised in question nos. (i) to (v), keeping in mind the distances between various
blocks/locations and other given parameters.

Distance between various blocks/locations:


Block Distance
App development to Web Designing 28 m
App development to Movie Editing 55 m
Web Designing to Movie Editing 32 m
Kashipur Campus to Mussoorie Campus 232 KM

Number of Computers:
Block Number of Computers
App Development 75
Web Designing 50
Movie Editing 80

i. Suggest the most appropriate block/location to house the SERVER in the


Kashipur campus (out of the 3 blocks) to get the best and effective
connectivity. Justify your answer.
ii. Suggest a device/software to be installed in the Kashipur Campus to take care
of data security.

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 47


iii. Suggest the best wired medium and draw the cable layout (Block to Block) to
economically connect various blocks within the Kashipur Campus.
iv. Suggest the placement of the following devices with appropriate reasons:
a) Switch / Hub
b) Repeater
v.
A. Suggest a protocol that shall be needed to provide Video Conferencing
solution between Kashipur Campus and Mussoorie Campus.
OR
B. Suggest network type (out of LAN, MAN, WAN) for connecting
Kashipur Campus to Mussoorie Campus
13. Hill Tech Services is planning to set up its India campus at Jaipur with its Head Office
at Mumbai. The Jaipur campus has 3-main blocks-HR, Technical and Marketing. You
as a network expert have to suggest the best network related solutions for their
problems raised in (i) to (v).

Jaipur Campus

Marketing Mumbai

HR

Head Office

Technical

Distance between various building blocks:

HR BLOCK to TECHNICAL BLOCK 45 m

HR BLOCK to MARKETING BLOCK 98 m

TECHNICAL BLOCK to MARKETING BLOCK 107 m

Head Office to JAIPUR Campus 1275 KM

Number of computers in each Block:

HR BLOCK 10

TECHNICAL BLOCK 105

MARKETING BLOCK 45

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 48


(i) Suggest the most appropriate location of the server inside the JAIPUR campus
(out of the 3 blocks), to get the best connectivity for maximum number of computers.
Justify your answer.

(ii) Which device will you suggest to be procured by the company for connecting all
the computers within each of their offices out of the following devices?
● Switch/Hub
● Modem
● Bridge
(iii) Suggest network type (out of LAN, MAN, WAN) for connecting each of the
following set of their offices:
⮚ HR & Marketing Block
⮚ Head Office and Jaipur Office

(iv) Which of the following communication medium, you will suggest to be procured
by the company for connecting their local offices in Jaipur for very effective and fast
communication?
● Telephone cable
● Optical fiber
● Ethernet cable
(v) Suggest and draw the cable layout (Block to Block) to connect various offices
within the Jaipur Campus.

14. Superior Education Society is an educational Organization. It is planning to setup its


Campus at Nagpur with its head office at Mumbai. The Nagpur Campus has 4 main
buildings – ADMIN, COMMERCE, ARTS and SCIENCE.
You as a network expert have to suggest the best network related solutions for their
problems raised in a to e, keeping in mind the distances between the buildings and
other given parameters:

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 49


Shortest distances between various buildings:
ADMIN to COMMERCE - 55 m
ADMIN to ARTS - 90 m
ADMIN to SCIENCE - 50 m
COMERCE to ARTS - 55 m
COMMERCE to SCIENCE - 50 m
ARTS to SCIENCE - 45 m
MUMBAI Head Office to NAGPUR Campus – 850 KM

Number of Computers installed at various buildings are as follows:


ADMIN – 110
COMMERCE – 75
ARTS – 40
SCIENCE – 12
MUMBAI Head Office – 20

i. Suggest the most appropriate location of the server inside the Nagpur Campus
to get the best connectivity for maximum number of computers. Justify your
answer.

ii. Suggest and draw the cable layout to efficiently connect various buildings
within the Nagpur campus for connecting the computers.

iii. Which of the following will you suggest to establish the online face-to-face
communication between the people in the ADMIN office of Nagpur Campus
and Mumbai Head office?
a) Cable TV
b) E-mail
c) Video Conferencing
d) Text Chat

iv. Suggest the placement of following devices with appropriate reasons:


⮚ Switch/Hub
⮚ Repeater

v. Suggest the device/software to be installed in Nagpur Campus to take care of


data security and unauthorized access.

15. Deccan Tech Services is planning to set up its India campus at Delhi with its Head
Office at Mumbai. The Delhi campus has 4-main blocks-BUSINESS, TECHNOLOGY,
LAW and HR. You as a network expert have to suggest the best network related
solutions for their problems raised in (i) to (v).

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 50


DELHI CAMPUS
LAW

MUMBAI
Head Office
TECHNOLOGY
BUSINESS

HR

Distance between various building blocks:


LAW BLOCK to BUSINESS BLOCK 40 m
LAW BLOCK to TECHNOLOGY BLOCK 80 m
LAW BLOCK to HR BLOCK 105 m
BUSINESS BLOCK to TECHNOLOGY BLOCK 30 m
BUSINESS BLOCK to HR BLOCK 35 m
TECHNOLOGY BLOCK to HR BLOCK 15 m
Head Office to Delhi Campus 1485 KM

Number of computers in each of the Blocks:


LAW BLOCK 15
TECHNOLOGY BLOCK 45
HR BLOCK 100
BUSINESS BLOCK 30

i. Suggest the most appropriate location of the server inside the DELHI campus
(out of the 4 blocks), to get the best connectivity for maximum number of
computers. Justify your answer.
ii. Suggest and draw the cable layout to efficiently connect various blocks within
the DELHI campus for connecting the computers.
iii. Which hardware device will you suggest to be procured by the company to be
installed to protect and control the internet uses within the campus?
iv. Suggest network type (out of LAN, MAN, WAN) for connecting each of the
following set of their offices:
⮚ Law & Technology Department

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 51


⮚ Head Office and Delhi Office
v. Company wants to connect its local offices situated in Delhi. Company can
compromise with speed but cost of connectivity should be economic. Which of
the following communication medium, you will suggest to be procured by the
company:
a) Telephone cable
b) Twisted Pair Cable
c) Optical Fiber Cable

16. “India Computer Ltd.” is a software services provider company. It is planning to start
its offices in four major cities in India to provide regional IT infrastructure. The
company has planned to setup their head office in New Delhi at three locations and
have named their New Delhi offices as “Sales Office”, “Head Office” and “Tech
Office”. The company’s regional offices are located in “Bengaluru”, “Kolkata” and
“Ahmedabad”. A rough layout of the same is as follows:

Distance between various locations:


From To Distance
Head Office Sales Office 110 Meter
Head Office Tech Office 20 Meter
Head Office Kolkata Office 1567 KM
Head Office Ahmedabad Office 900 KM
Head Office Bengaluru Office 2110 KM

Number of computers installed at various locations:


Head Office 90
Sales Office 20
Tech Office 50
Kolkata Office 40
Ahmedabad Office 25
Bengaluru Office 30

You as a networking expert need to suggest solutions to the questions in part (i) to
(v), keeping in mind the distances and other given parameters:

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 52


i. Suggest network type (out of LAN, MAN, WAN) for connecting each of the
following set of their offices:
a. Head office and Tech office
b. Head office and Bengaluru office

ii. Which block in New Delhi should host the server? Justify your answer.

iii. Which wired communication media, you will suggest to be used by the
company to connect its local offices in New Delhi for very effective and fast
communication?

iv. Suggest and draw a cable/wiring layout for connecting the local offices located
in New Delhi for connecting the digital devices.
v. In New Delhi Campus, in between which offices repeater should be installed?
Justify the answer.
17. Aman is a Python programmer. He has written a code and created a binary file
record.dat with employeeid, ename and salary. The file contains 10 records.
He now has to update a record based on the employee id entered by the user and
update the salary. The updated record is then to be written in the file temp.dat. The
records which are not to be updated also have to be written to the file temp.dat. If
the employee id is not found, an appropriate message should to be displayed.
As a Python expert, help him to complete the following code based on the
requirement given above:
import _______ #Statement 1
def update_data():
rec={}
fin=open("record.dat","rb")
fout=open("_____________") #Statement 2
found=False
eid=int(input("Enter employee id to update their salary :: "))
while True:
try:
rec=______________ #Statement 3
if rec["Employee id"]==eid:
found=True
rec["Salary"]=int(input("Enter new salary :: "))
pickle.____________ #Statement 4
else:
pickle.dump(rec,fout)
except:
break
if found==True:
print("The salary of employee id ",eid," has been updated.")
else:
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 53
print("No employee with such id is not found")
fin.close()
fout.close()

i. Which module should be imported in the program? (Statement 1)


ii. Write the correct statement required to open a temporary file named
temp.dat. (Statement 2)
iii. Which statement should Aman fill in Statement 3 to read the data from the
binary file, record.dat and in Statement 4 to write the updated data in the file,
temp.dat?

18. Alok Kumar of class 12 is writing a program to create a CSV file “project.csv” which
will contain student name and project name for some entries. He has written the
following code. As a programmer, help him to successfully execute the given task.

import _____________ # Line 1


def AddProject (StudentName, ProjectName): # to write data into the CSV file
f=open(' project.csv', '________') # Line 2
newFileWriter = csv.writer(f)
newFileWriter.writerow([Sname,Pname])
f.close( )

#csv file reading code


def ReadProject( ): # to read data from CSV file
with open(' project.csv', 'r') as newFile:
newFileReader = csv._________(newFile) # Line 3
for row in newFileReader:
print (row[0],row[1])
newFile.______________ # Line 4

AddProject(“Ranjana”, “Traffic Control System”)


AddProject(“Ankit”, “Parking Allotment Problem”)
AddProject(“Krishna”, “Billing System”)
ReadProject( )

i. Name the module he should import in Line 1.


ii. In which mode he has to open the file in Line-2, to add data into the file.
iii. Fill in the blank in Line 3 to read the data from a csv file.
iv. Fill in the blank in Line 4 to close the file.
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 54
19. Tarun Nair is working under XYZ Incorporation which deals with exporting of goods
to foreign countries. To keep track of inventory he is creating a Python program to
store the information of item number and quantity in a binary file inventory.dat. For
that he has written the following code. Go through the code given and solve problems
given below:

def write(ino,qty):
F = open(____________) #Mark 2
L= _______________ #Mark 3
L.append([ino,qty])
F.close()
F=open('inventory.dat','wb')
pickle.dump(L,F)
F.close()

def Receive(ino,qty):
F=open(“inventory.dat”,”rb”)
L=pickle.load(F)
F.close()
for i in range(len(L)):
if L[i][0] == ino:
L[i][1] += qty
F=open("inventory.dat",'wb')
pickle.dump(L,F)
________________ #Mark 4

def Sent(ino,qty):
with open(“inventory.dat”, “rb”) as F:
L=pickle.load(F)
for i in range(len(L)):
if L[i][0] == ino:
L[i][1] -= qty
with open("inventory.dat",'wb') as F:
pickle.dump(L,F)

i. Write statement to open the file at Mark 2 to read records from the file.
ii. Write statement at Mark 3 to read the content of binary file in list L.
iii. Write statement at Mark 4 to close the file. Why there is no need to close the
file in function Sent()?

BY:
VIKASH KUMAR YADAV
PGT-COMPUTER SCIENCE
PM SHRI K.V. O.F. CHANDA

By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 55

You might also like