KV Computer
KV Computer
KV Computer
CHIEF PATRON
Dr D MANJUNATH, DEPUTY COMMISSIONER
PATRON
Mr T PRABHUDAS, ASSISTANT COMMISSIONER
CO ORDINATOR
SRI HONEY MEHTA, PRINCIPAL, KV GUNTUR
COMPILED BY:
Mrs M CELINA SOWJANYA, PGT CS, KV GUNTUR
2
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
UNIT-1 COMPUTATIONAL THINKING AND PROGRAMMING – 2
a) 15 b) 10 c) 5 d) 0
4. What will be the output of the following code?
numbers = [1, 2, 3, 4, 5]
for i in range(len(numbers)):
numbers[i] *= 2
print(numbers)
a) 9 b) 6 c) 5 d) 0
6. What will be the output of the following code?
word = "Python"
reversed_word = ""
for char in word:
reversed_word = char + reversed_word
print(reversed_word)
10. Which of the following options correctly merges two lists in Python?
13. Which of the following options correctly splits a string into a list of words in Python?
20. What is the data type of the result after executing the following code?
x = "Hello"
y=3
result = x * y
a) str b) int c) bool d) None
26. Which one of the following is the correct way of calling a function?
A) built-in functions
B) user-defined functions
C) control functions
D) None of the above
my_func()
a) 10 8 6 4 2 b) 10 9 8 7 6 5 4 3 2 1 c) 10 7 4 1 d) 10 5
print_pattern(4)
countdown(5)
a) 5 4 b) 5 4 3 c) 5 4 3 2 1 Blastoff! d) 5 4 3 Blastoff!
32. What will be the output of the following code?
def compute_average(numbers):
total = 0
count = 0
for num in numbers:
total += num
count += 1
6
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
return total / count
print_table(3)
7
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
result = fibonacci(8)
print(result)
a) [0, 1, 1, 2, 3, 5, 8] b) [0, 1, 1, 2, 3, 5, 8, 13] c) [0, 1, 2, 3, 5, 8] d) [0, 1, 2, 3, 5, 8, 13]
result = factorial(5)
print(result)
a) Computes the sum of numbers from 1 to 5. b) Computes the product of numbers from 1 to 5.
c) Calculates the factorial of 5. d) Raises 5 to the power of 5.
foo()
print(a)
a) 5 b) 6 c) 10 d) NameError: name 'a' is not defined
40. What is the output of the following code snippet?
def multiply(a, b):
return a * b
result = calculate(4, 5)
print(result)
a) 9 b) 20 c) 45 d) 25
EXCEPTION HANDLING
41. What is an exception in Python?
a) An error b) A warning c) A function d) A class
8
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
44. Which of the following is not an exception handling clause in Python?
a) try b) except c) else d) throw
45. What will be the output of the following code?
try:
print(10 / 0)
except ZeroDivisionError:
print("Error: Division by zero")
a) Error: Division by zero b) Error: Index out of range c) 10 d) None of the above
46. In a try-except block, if an exception occurs but it is not handled by any except clause, what
happens?
a) The program terminates b) The exception is ignored
c) The program continues to execute normally d) None of the above
47. Which keyword is used to define a block of code that will be executed if no exceptions are raised?
a) try b) catch c) else d) finally
48. What is the purpose of the 'except' clause in a try-except statement?
a) To define alternative code b) To specify the type of exception to handle
c) To handle multiple exceptions d) To execute cleanup code
49. Which of the following statements is true about nested try-except blocks?
a) Only one try block can be nested inside another try block
b) Only one except block can be nested inside another except block
c) A try block can be nested inside another try block, and an except block can be nested inside
another except block
d) Nesting try-except blocks is not allowed in Python
50. 10. Which exception is raised when an incorrect type of argument is passed to a function in
Python?
a) ValueError b) TypeError c) AttributeError d) NameError
51. What will be the output of the following code?
try:
print(10 / 0)
except ZeroDivisionError as e:
print("Error:", str(e))
finally:
print("Finally block")
divide(10, 0)
a) Error: Division by zero b) Finally block
Finally block
c) The code will raise an exception and terminate. d) None of the above.
11
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
60. What will be the output of the following code?
try:
raise NameError("Custom Error")
except ValueError:
print("Error: ValueError")
except NameError:
print("Error: NameError")
else:
print("No error")
a) Error: ValueError b) Error: NameError
c) No error d) The code will raise an exception and terminate.
62. What is the correct syntax to open a file named "data.txt" in write mode in Python?
63. Which method is used to read a single line from a file object in Python?
64. Which of the following modes in file handling allows both reading and writing to a file in Python?
67. What is the correct way to close a file object after reading or writing in Python?
68. Which method is used to check the current position of the file pointer in Python?
69. How can you read the contents of a file line by line in Python?
13
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
A) Opens the "data.txt" file in read mode, reads its contents, and appends "Hello, World!" to the
file.
B) Opens the "data.txt" file in write mode, writes "Hello, World!" to the file, and closes the file.
C) Opens the "data.txt" file in append mode, appends "Hello, World!" to the file, and closes the file.
D) Opens the "data.txt" file in append mode, reads its contents, and appends "Hello, World!" to the
file.
A) Opens the "data.txt" file in write mode, reads the number of lines in the file, closes the file,
and prints the count.
B) Opens the "data.txt" file in read mode, reads the number of lines in the file, closes the file, and
prints the count.
C) Opens the "data.txt" file in append mode, reads the number of lines in the file, closes the file,
and prints the count.
D) Opens the "data.txt" file in read mode, writes the number of lines in the file, closes the file,
and prints the count.
79. Consider the following code snippet:
file = open("data.txt", "w")
file.writelines(["Hello\n", "World\n"])
file.close()
A) Opens the "data.txt" file in read mode, reads and prints each line without any leading or
trailing whitespace, and closes the file.
B) Opens the "data.txt" file in read mode, reads and prints each line with leading and trailing
whitespace, and closes the file.
C) Opens the "data.txt" file in write mode, writes each line to the file without any leading or
trailing whitespace, and closes the file.
D) Opens the "data.txt" file in append mode, appends each line to the file with leading and
trailing whitespace, and closes the file.
14
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
DATA FILE HANDLING - BINARY FILES
81. Which of the following modes should be used when opening a binary file for reading?
a) "r" b) "rb" c) "read" d) "binary"
82. Which of the following code snippets correctly opens a binary file named "data.bin" in write mode
and writes binary data into it?
a) file = open("data.bin", "write")
file.write(b'\x00\x01\x02')
file.close()
b) When you open binary file in text editor will show garbage values
a) wb mode is used to open binary file in write mode and wb+ mode open binary file both for read
and write operation.
b) In wb mode file open in write mode and wb+ in read mode
c) File pointer is at beginning of file in wb mode and in wb+ at the end of file
d) No difference
85. The pickle module in Python is used for?
86. Which method is used to convert Python objects for writing data in binary file?
a) r b) rb c) wb d) wb+
15
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
88. Which of the following function is used to read the data in binary file?
91. Which of the following code snippets correctly opens a binary file named "data.bin" in append
mode and appends binary data to it?
93. Which of the following statements is true about binary file handling in Python?
a) Binary files can only be read, not written.
b) Binary files can only be written, not read.
c) Binary files can be both read and written.
d) Binary files are not supported in Python.
94. What happens if you try to open a non-existent binary file in read mode?
a) An error is raised.
b) An empty binary file is created.
c) The file is created automatically.
d) The program continues to run without any issues.
95. Which method is used to check if the end of a binary file has been reached?
a) is_end_of_file() b) end_of_file() c) eof() d) at_end()
96. Which method is used to get the size of a binary file in Python?
a) get_size() b) size() c) file_size() d) os.path.getsize()
97. Which method is used to move the file pointer to the beginning of a binary file?
a) start() b) move_to_start() c) seek(0) d) seek(1)
98. What is the purpose of the flush() method in binary file handling?
a) To write binary data to a file.
16
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
b) To check if a file exists.
c) To get the current position of the file pointer.
d) To ensure that all data is written to the file.
99. What is the purpose of the is_closed() method in binary file handling?
a) To check if a binary file has been opened. b) To check if a binary file is read-only.
c) To check if a binary file exists. d) To check if a binary file has been closed.
100. Which of the following code snippets correctly opens a binary file named "data.bin" in read mode
and moves the file pointer to the 10th byte?
102. To open a CSV file in Python, which function should you use?
a) open() b) read_csv() c) csv.reader() d) load_csv()
103. How can you read a CSV file using the `csv` module in Python?
a) csv.read() b) csv.load() c) csv.reader() d) csv.open()
105. Which method is used to iterate over the rows of a CSV file using the `csv.reader()` object?
a) next() b) read() c) iterate() d) for loop
17
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
107. How do you write a header row in a CSV file using the `csv.writer` object?
a) Use the `writeheader()` method b) Use the `write_row()` method
c) Use the `write()` method d) Use the `header()` method
109. How can you specify a different delimiter character when writing a CSV file using the `csv.writer`
object?
a) It is not possible to change the delimiter
b) Use the `delimiter` parameter in the `csv.writer()` function
c) Use the `set_delimiter()` method after creating the `csv.writer` object
d) Use the `change_delimiter()` method before calling the `write()` method
110. How can you handle special characters in a CSV file using the `csv.writer` object?
a) Special characters are automatically handled
b) Use the `handle_special_chars()` method before calling the `write()` method
c) Use the `quotechar` parameter in the `csv.writer()` function
d) Special characters are not allowed in CSV files
111. What does the `newline` parameter in the `open()` function do when working with CSV files?
a) It specifies the character encoding of the CSV file
b) It sets the file mode to binary
c) It controls how universal newlines are handled
d) It indicates the number of newlines to append to the file
112. How can you close a CSV file after you have finished working with it?
a) Use the `close()` method on the `csv.reader` object
b) Use the `close()` method on the `csv.writer` object
c) Use the `close()` method on the file object returned by `open()`
d) CSV files are automatically closed when the program finishes
113. What is the recommended way to handle exceptions when working with CSV files?
a) Ignore exceptions as they are rare in CSV file handling
b) Use the `try-except` block to catch and handle exceptions
c) Use the `csv.exception()` function to handle exceptions
d) Exception handling is not necessary when working with CSV files
114. How can you skip the header row when reading a CSV file using the `csv.reader` object?
a) Use the `skip_header()` method before iterating over rows
b) Use the `skiprow` parameter in the `csv.reader()` function
c) Skip the first row manually in the `for` loop
d) CSV files do not have header rows
115. What is the purpose of the `Dialect` class in the `csv` module?
a) It defines the format of a CSV file
b) It provides methods to manipulate CSV files
c) It handles errors and exceptions in CSV file handling
d) The `Dialect` class is not used in the `csv` module
116. How can you read a CSV file into a list of dictionaries in Python?
a) Use the `csv.reader` object directly
b) Use the `csv.DictReader` object
c) Use the `read_csv()` function from the `pandas` library
d) Convert each row manually into a dictionary
117. 17. What is the difference between `csv.reader` and `csv.DictReader`?
a) `csv.reader` returns a list of lists, while `csv.DictReader` returns a list of dictionaries
b) `csv.reader` is used for reading CSV files, while `csv.DictReader` is used for writing CSV
files
18
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
c) There is no difference; they can be used interchangeably
d) `csv.reader` is a class, while `csv.DictReader` is a function
118. Which method is used to write a row of data in a CSV file using the `csv.DictWriter` object?
a) write_row() b) write_rowdata() c) write_dict() d) writerow()
119. How can you specify the fieldnames for a CSV file using the `csv.DictWriter` object?
a) Pass them as a list to the `fieldnames` parameter in the `csv.DictWriter()` function
b) Use the `set_fieldnames()` method after creating the `csv.DictWriter` object
c) Specify them as the first row in the CSV file
d) Fieldnames are not required when using the `csv.DictWriter` object
120. How can you handle quoted values in a CSV file using the `csv` module in Python?
a) Quoted values are automatically handled by the `csv.reader` object
b) Use the `handle_quoted_values()` method before reading the file
c) Use the `quotechar` parameter in the `csv.reader()` function
d) Quoted values are not supported in CSV files
DATA STRUCTURES
121 Process of inserting an element in stack is called _____________
123 In a stack, if a user tries to remove an element from empty stack it is called _____________
124 Pushinganelementintostackalreadyhavingfiveelementsandstacksizeof5,thenstackbecomes
a) Overflow b)Crash c)Underflow d) Userflow
125 Entries in a stack are “ordered”. What is the meaning of this statement?
a) A collection of stacks is sortable
b) Stack entries may be compared with the„<„operation
c) The entries are stored in a linked list
d) There is a Sequential entry that is one by one
127 Consider the usual algorithm for determining whether a sequence of parentheses is balanced.
The maximum number of parentheses that appear on the stack AT ANY ONE TIME when the
algorithm analyzes:
(()(())(()))are:
a) 1 b)2 c)3 d)4 or more
128 Consider the usual algorithm for determining whether a sequence of parentheses is balanced.
Suppose that you run the algorithm on a sequence that contains 2 left parentheses and 3 right
parentheses (in some order).The maximum number of parentheses that appear on the stack
AT ANY ONE TIME during the computation?
a) 1 b)2 c)3 d) 4 or more
19
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
129 What is the valueofthepostfixexpression6 32 4 +–*:
a) Something between -5and -15 b)Something between 5and -5
c)Something between 5 and 15 d)Something between 15 and
100
130 Here is an infix expression: 4 + 3*(6*3-12). Suppose that we are using the usual stack
algorithm to convert the expression from infix to post fix notation.
The maximum number of symbols that will appear on the stack AT ONE TIME during the
conversion of this expression?
a) 1 b)2 c)3 d)4
131 A linear list of elements in which deletion can be done from one end (front) and insertion can
take place only at the other end(rear)is known as a___________
a) Queue b)Stack c)Tree d) Linkedlist
134 A data structure in which elements can be inserted or deleted at / from both the ends but not in the
middle is?
a) Queue b) Circular queue c) Dequeue d) Priority queue
137 Here is an infix expression: 4 + 3*(6*3-12). Suppose that we are using the usual stack algorithm
to convert the expression from infix to postfix notation. The maximum number of symbols that
will appear on the stack AT ONE TIME during the conversion of this expression?
a) 1 b) 2 c) 3 d) 4
138 Convert the following infix expressions into its equivalent postfix expressions.
(A + B ⋀ D)/(E – F)+G
a) (A B D ⋀ + E F – / G +) b) (A B D +⋀ E F – / G +)
c) (A B D ⋀ + E F/- G +) d) (A B D E F + ⋀ / – G +)
20
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
INTERFACE PYTHON WITH SQL, DATABASE MANAGEMENT SYSTEM
141 Which of the following package must be imported in Python to create a database connectivity
application?
a) mysql.connector b) mysql.connect c) sql.connector d) sql.execute
142 Which of the following component act as a container to hold all the data returned from the query
and from there we can fetch data one at a time?
a)ResultSet b). Cursor c.) Container d). Table
143 Which attribute of cursor is used to get number of records stored in cursor (Assuming cursor name
is mycursor)?
a. mycursor.count b. mycursor.row_count c. mycursor.records d. mycursor.rowcount
144 To make the changes made by any SQL Queries permanently in database, which function is used
after execution of the query ?
a) save() b) commit() c) execute() d) dump()
148 Which of the following function is used to FIND the largest value from the given data in MYSQL?
a) MAX () b) MAXIMUM () c) LARGEST () d) BIG ()
149 The data types CHAR (n) and VARCHAR (n) are used to create _______ and _______ types of
string/text fields in a database.
a) Fixed, equal b) Equal, variable c) Fixed, variable d) Variable, equal
150 SELECT name FROM stu WHERE subject LIKE „_______ Computer Science‟;
Which one of the following has to be added into the blank space to select the subject which has
Computer Science as its ending string?
a) $ b) _ c) || d) %
153 Select correct SQL query from below to find the temperature in increasing order of all cites(Table
name:weather).
a) SELECT city, temperature FROM weather ORDER temperature;
b) SELECT city, temperature FROM weather ASC;
c) SELECT city, temperature FROM weather ORDER BY temperature;
d) SELECT city, temperature FROM weather ORDER BY city;
21
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
154 An attribute in a relation is foreign key if it is the _________key in any other relation.
a) Candidate b) Primary c) Super d) Sub
157 Which SQL function is used to count the number of rows in a SQL query?
a) COUNT () b) NUMBER () c) SUM () d) COUNT (*)
160 Which join combines each row from the first table with every row from the right table to make the
result set?
a. CROSS JOIN b.OUTER JOIN c. INNER JOIN d.EQUI JOIN
162 In SQL, this function returns the time at which the function executes:
A. SYSDATE B. NOW C. CURRENT D. TIME
163 Which type of values will not considered by SQL while executing the following statement?
SELECT COUNT(column name) FROM INVENTORY;
A. Numeric value B. Text value C. Null value D. Date value
166 The correct SQL from below to find the temperature in increasing order of all cities.
A. SELECT city FROM weather order by temperature;
B. SELECT city, temperature FROM weather;
C. SELECT city, temperature FROM weather ORDER BY temperature;
D. SELECT city, temperature FROM weather ORDER BY city;
22
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
167 Which of the following is not a category of MySQL functions?
A. Text Functions B. Mathematical Functions
C. Statistical Functions D. Arithmetic Functions
168 Where and Having clauses can be used interchangeably in SELECT queries?
A. True B. False C. Only in views D. With order by
169 Which SQL statement is used to display all the data from product table in the decreasing order of
price?
A. SELECT * FROM PRODUCT;
B. SELECT * FROM PRODUCT ORDER BY PRICE;
C. SELECT * FROM PRODUCT ORDER BY PRICE DESC;
D. SELECT * FROM PRODUCT ORDER BY DESC;
COMPUTER NETWORKS
172 What was the first network that laid the foundation for the modern Internet?
a) ARPANET b) NSFNET c) INTERNET d) WWWNET
173 In which switching technique is data divided into small packets before transmission?
a) Circuit switching b) Packet switching
c) Virtual switching d) Frequency switching
175 What is the unit used to measure the data transfer rate of a communication channel?
a) Bandwidth b) Hertz c) Baud d) Mbps
176 Which transmission media is known for its high bandwidth and immunity to electromagnetic
interference?
a) Twisted pair cable b) Co-axial cable c) Fiber-optic cable d) Radio waves
23
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
178 Which network device operates at the physical layer of the OSI model?
a) Repeater b) Hub c) Switch d) Router
180 What does the acronym PAN stand for in computer networking?
a) Public Area Network b) Personal Area Network
c) Private Access Network d) Peer-to-Peer Network
181 Which protocol is used for transferring files over the internet?
a) HTTP b) FTP c) SMTP d) TCP/IP
183 Which network protocol is used for sending and receiving email?
a) PPP b) SMTP c) POP3 d) HTTPS
184 Which network protocol is used to establish a secure connection for websites?
a) FTP b) SMTP c) HTTPS d) TELNET
188 Which network type covers a small geographical area, like an office or a building?
a) PAN b) LAN c) MAN d) WAN
191 . Which device is used to regenerate the signals over long distance data transmission?
a)Switch b) Modem c) Repeater d) None of the above
193 A computer network created by connecting the computers of your school‟s computer lab is an
example of
a)LAN b) MAN c) WAN d) PAN
194 Which topology are all the nodes connected through a single coaxial cable?
a) Star b) Tree c) Bus d) Ring
196 An online activity that enables us to publish website or web application on the internet
a) Web server b) Web Browser c) Web Hosting d)None
198 The device used to connect two networks using different protocols is:
a) Router b) Repeater c) Gateway d)Hub
199 Which protocol allows you to make voice calls using a broadband Internet connection?
a)Chat b)ftp c)email d)VoIP
25
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
ANSWERS TO MCQs
Q.NO 1 2 3 4 5 6 7 8 9 10
ANSWER B C A B A B A A A A
Q.NO 11 12 13 14 15 16 17 18 19 20
ANSWER B A D A A A D A A A
QNO 21 22 23 24 25 26 27 28 29 30
ANSWER D A B C B A B B A A
QNO 31 32 33 34 35 36 37 38 39 40
ANSWER D B A C B A A C B B
QNO 41 42 43 44 45 46 47 48 49 50
ANSWER A C C D A A C B C B
QNO 51 52 53 54 55 56 57 58 59 60
ANSWER A A B C A B A A A B
QNO 61 62 63 64 65 66 67 68 69 70
ANSWER B B B D B A A C A A
QNO 71 72 73 74 75 76 77 78 79 80
ANSWER C D A D A B C B A A
QNO 81 82 83 84 85 86 87 88 89 90
ANSWER B B C A C D A D D A
QNO 91 92 93 94 95 96 97 98 99 100
ANSWER B A C A C D C D D A
QNO 101 102 103 104 105 106 107 108 109 110
ANSWER C A C A D B A C B C
QNO 111 112 113 114 115 116 117 118 119 120
ANSWER C C B C A B A D A C
QNO 121 122 123 124 125 126 127 128 129 130
ANSWER B D A A D D C B D D
QNO 131 132 133 134 135 136 137 138 139 140
ANSWER A A A C D D D A B A
QNO 141 142 143 144 145 146 147 148 149 150
ANSWER A B D B A C C A C D
QNO 151 152 153 154 155 156 157 158 159 160
ANSWER B A C B B C D B C A
QNO 161 162 163 164 165 166 167 168 169 170
ANSWER C A C D D D D B C A
QNO 171 172 173 174 175 176 177 178 179 180
ANSWER A A B C D C C A A B
QNO 181 182 183 184 185 186 187 188 189 190
ANSWER B C B C A D A B B A
QNO 191 192 193 194 195 196 197 198 199 200
ANSWER V B A C B C B C D D
26
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
COMPETENCY BASED QUESTIONS
27
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
CLASS XI REVISION TOUR – CASE BASED QUESTIONS
1. You have a list of names ["Alice", "Bob", "Charlie", "David"]. You want to print only the names
that have more than 4 characters using a 'for loop'. Which of the following code snippets
accomplishes this?
a) names = ["Alice", "Bob", "Charlie", "David"]
for name in names:
if len(name) > 4:
print(name)
b) names = ["Alice", "Bob", "Charlie", "David"]
for i in range(len(names)):
if len(names[i]) > 4:
print(names[i])
c) names = ["Alice", "Bob", "Charlie", "David"]
for i in names:
if len(i) > 4:
print(i)
d) names = ["Alice", "Bob", "Charlie", "David"]
for name in range(names):
if len(name) > 4:
print(name)
2. You are building a program to analyze a given text string and count the occurrences of a specific
word within it. The word to be searched is provided by the user. You decide to use a 'for loop' to
iterate over each word in the string and compare it with the given word. Which of the following
code snippets correctly implements this functionality?
a) text = "The quick brown fox jumps over the lazy dog"
word = input("Enter a word to search: ")
count = 0
for char in text:
if char == word:
count += 1
print("Occurrences of the word:", count)
b) text = "The quick brown fox jumps over the lazy dog"
word = input("Enter a word to search: ")
count = 0
for word in text.split():
if word == word:
count += 1
print("Occurrences of the word:", count)
c) text = "The quick brown fox jumps over the lazy dog"
word = input("Enter a word to search: ")
count = 0
for word in text:
if word == word:
count += 1
print("Occurrences of the word:", count)
d) text = "The quick brown fox jumps over the lazy dog"
28
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
word = input("Enter a word to search: ")
count = 0
for word in text.split():
if word == word:
count += 1
print("Occurrences of the word:", count)
3. You are developing a program to store and analyze student data. Each student's information includes
their name, age, and grade. You decide to use tuples to represent each student's data. Which of the
following code snippets correctly defines a tuple for a student named "Alice" who is 16 years old
and in 11th class?
29
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
d) inventory = {}
item_code = input("Enter item code: ")
item_name = input("Enter item name: ")
item_price = float(input("Enter item price: "))
item_quantity = int(input("Enter item quantity: "))
item_details = dict(name=item_name, price=item_price, quantity=item_quantity)
inventory[item_code] = item_details
5. You are developing a program that stores information about books in a library. Each book has
attributes such as title, author, publication year, and availability status. You decide to use different
data types to represent these attributes. Which of the following code snippets correctly demonstrates
the usage of appropriate data types for the book attributes?
a) book = {
"title": "Python Programming",
"author": "John Doe",
"publication_year": "2020",
"availability": True
}
b) book = {
"title": "Python Programming",
"author": "John Doe",
"publication_year": 2020,
"availability": "Yes"
}
c) book = {
"title": "Python Programming",
"author": "John Doe",
"publication_year": 2020,
"availability": True
}
d) book = {
"title": "Python Programming",
"author": "John Doe",
"publication_year": "2020",
"availability": "Available"
}
Q.NO ANSWER
1. A
2. D
3. A
4. B
5. C
30
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
FUNCTIONS – CASE BASED QUESTIONS
1. You are tasked with creating a function that calculates the average of a list of numbers. Which of
the following code snippets correctly defines and calls this function?
a) def calculate_average(numbers):
total = sum(numbers)
average = total / len(numbers)
return average
result = calculate_average(1, 2, 3, 4, 5)
c) def calculate_average(*numbers):
total = 0
for num in numbers:
total += num
average = total / len(numbers)
return average
result = is_palindrome("racecar")
b) def is_palindrome(string):
reversed_string = ""
31
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
for char in string:
reversed_string = char + reversed_string
if string == reversed_string:
return True
else:
return False
result = is_palindrome("hello")
c) def is_palindrome(string):
if string == string.reverse():
return True
else:
return False
result = is_palindrome("level")
d) def is_palindrome(string):
if string == string[::-1]:
return True
else:
return False
result = is_palindrome("python")
3. You are developing a program that requires a function to calculate the factorial of a given number.
Which of the following code snippets correctly defines and calls this function?
a) def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
result = factorial(5)
b) def factorial(n):
result = 1
for i in range(1, n + 1):
result *= i
return result
result = factorial(5)
c) def factorial(n):
result = n
while n > 1:
n -= 1
result *= n
return result
result = factorial(5)
d) def factorial(n):
result = 1
while n > 0:
32
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
result *= n
n -= 1
return result
result = factorial(5)
4. You want to create a function that accepts a list of numbers and returns a new list containing only
the even numbers from the original list. Which of the following code snippets correctly implements
this function?
a) def get_even_numbers(numbers):
even_numbers = []
for num in numbers:
if num % 2 == 0:
even_numbers.append(num)
return even_numbers
b) def get_even_numbers(numbers):
even_numbers = []
for i in range(len(numbers)):
if numbers[i] % 2 == 0:
even_numbers.append(numbers[i])
return even_numbers
c) def get_even_numbers(numbers):
even_numbers = []
for num in range(numbers):
if num % 2 == 0:
even_numbers.append(num)
return even_numbers
d) def get_even_numbers(numbers):
even_numbers = []
for num in numbers:
if numbers % 2 == 0:
even_numbers.append(num)
return even_numbers
5. You are creating a program that calculates the area of different shapes. You decide to create
separate functions for each shape. Which of the following code snippets correctly defines and calls
a function to calculate the area of a rectangle?
a) def calculate_rectangle_area(length, width):
area = length * width
return area
result = calculate_rectangle_area(5, 6)
33
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
b) def calculate_rectangle_area(side):
area = side * side
return area
result = calculate_rectangle_area(5)
c) def calculate_rectangle_area(length, width):
area = length + width
return area
result = calculate_rectangle_area(5, 6)
d) def calculate_rectangle_area(side):
area = side + side
return area
result = calculate_rectangle_area(5)
6 Anil, a student of class 12th, is learning Pythonfunctions . During examination, he has been
assigned an incomplete python code (shown below) for finding max of given two numbers. Help
him to complete the following code
defmax_of_two( x, y ):
if ______:
return x
else:
return y
7 Ravi, is a student of class 12th, is learning Python functions . During examination, he has been
assigned an incomplete python code (shown below) for finding Sum of numbers in the given list.
Help him to complete the following code
def sum(numbers):
total = 0
for x in numbers:
_________
return total
print(sum((8, 2, 3, 0, 7)))
8 Mahesh, is a student of class 12th, is learning Python functions . During examination, he has been
assigned an incomplete python code (shown below) for searching element in the given list. Help
him to complete the following code
defSearch(Nums, ele):
if ele in Nums :
return ______
else:
return False
print(Srearch(Nums,20))
34
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
9 Tarun, is a student of class 12th, is learning Python functions . During examination, he has been
assigned an incomplete python code (shown below) to check given string is a palindrome or not.
Help him to complete the following code
defPalindrome(Name):
if ______________:
return True
else:
return False
def sum(N):
f=1
for x in _____:
f=f*x
return f
print(fact(5))
35
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
EXCEPTION HANDLING – CASE BASED QUESTIONS
1 You are building a calculator program that takes user input for two numbers and performs
arithmetic operations. Implement exception handling to handle cases where the user enters invalid
input.
Question:
How would you handle the scenario where the user enters a non-numeric value instead of a
number?
a) Use a try-except block to catch a `ValueError` and display an error message to the user.
b) Use a try-except block to catch a `TypeError` and display an error message to the user.
c) Use a try-except block to catch an `IndexError` and display an error message to the user.
d) Use a try-except block to catch a `SyntaxError` and display an error message to the user.
2 You are writing a program that reads data from a file and performs some calculations. Implement
exception handling to handle cases where the file does not exist.
Question:
How would you handle the scenario where the file specified by the user does not exist?
a) Use a try-except block to catch a `FileNotFoundError` and display an error message.
b) Use a try-except block to catch a `ValueError` and display an error message.
c) Use a try-except block to catch a `TypeError` and display an error message.
d) Use a try-except block to catch an `IndexError` and display an error message.
3 You are working on a program that receives network data. Implement exception handling to handle
cases where the network connection is lost.
Question:
How would you handle the scenario where the network connection is lost while receiving data?
a) Use a try-except block to catch a `ConnectionError` and attempt to reconnect.
b) Use a try-except block to catch a `ValueError` and display an error message.
c) Use a try-except block to catch a `TypeError` and display an error message.
d) Use a try-except block to catch an `IndexError` and display an error message.
4 You are building a web scraping program that extracts data from a website. Implement exception
handling to handle cases where the website is down or unreachable.
Question:
How would you handle the scenario where the website is down or unreachable?
a) Use a try-except block to catch a `ConnectionError` and display an error message.
b) Use a try-except block to catch a `FileNotFoundError` and display an error message.
c) Use a try-except block to catch a `TypeError` and display an error message.
d) Use a try-except block to catch a `ValueError` and display an error message.
5 You are writing a program that performs database operations. Implement exception handling to
handle cases where the database connection fails.
Question:
How would you handle the scenario where the database connection fails?
a) Use a try-except block to catch a `DatabaseError` and display an error message.
b) Use a try-except block to catch a `NameError` and display an error message.
c) Use a try-except block to catch a `SyntaxError` and display an error message.
d) Use a try-except block to catch a `ValueError` and display an error message.
6 The code shown below will result in an error if the input value is entered as -5. State whether this
statement is true or false.
assert False, 'Spanish'
a) True b) False
36
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
7 What is the output of the code shown below?
x=10
y=8
assert x>y, 'X too small'
a) Assertion Error b) 10 8 c) No output d) 108
8 What is the output of the code shown below?
#generator
def f(x):
yield x+1
g=f(8)
print(next(g))
a) 8 b) 9 c) 7 d) Error
9 What is the output of the code shown below?
def f(x):
yield x+1
print("test")
yield x+2
g=f(9)
a) Error b) test
c) test and 10 and 12 d) No output
10 What is the output of the code shown below?
def f(x):
yield x+1
print("test")
yield x+2
g=f(10)
print(next(g))
print(next(g))
a) No output b) 11 and test and 12
c) 11 and test d) 11
37
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
TEXT FILE HANDLING – CASE BASED QUESTIONS
1. A) Read the file using `file.read()` and then remove empty lines using a loop.
2. B) Use the `file.readlines()` method to read the file into a list and remove empty lines using a
loop.
3. C) Use the `file.read().splitlines()` method to read the file into a list, which automatically excludes
empty lines.
4. D) Read the file using `file.read()` and then use the `filter()` function to remove empty lines from
the resulting list.
2. Consider the following scenario:
You are working on a project that involves reading a text file with a large number of lines. You want
to process the file line by line efficiently, without loading the entire file into memory. Which
approach should you use?
1. A) Use the `file.read()` method to read the entire file and then iterate over the lines.
2. B) Use the `file.readlines()` method to read all the lines at once and then iterate over them.
3. C) Iterate over the file object directly without using any specific method for reading the lines.
4. D) Use the `file.readline()` method inside a loop to read and process each line sequentially.
3. Consider the following scenario:
You need to write a list of strings to a text file, where each string should be written as a separate
line. Which approach is recommended for achieving this?
1. A) Use the `file.write()` method to write each string, followed by a line break character.
2. B) Concatenate the strings into a single string with line break characters and then use the
`file.write()` method.
3. C) Use the `file.writelines()` method, passing the list of strings as an argument, without any
additional characters.
4. D) Iterate over the list of strings and use the `file.write()` method for each string, followed by a
line break character.
4. Which of the following code snippets correctly demonstrates the usage of a `with` statement to
automatically close a file after reading its content?
a) file = open("data.txt", "r")
content = file.read()
print(content)
file.close()
b) with open("data.txt", "r") as file:
content = file.read()
print(content)
c) with open("data.txt", "r") as file
content = file.read()
print(content)
d) file = open("data.txt", "r")
content = file.read()
print(content)
close(file)
5. Which of the following code snippets correctly opens a text file named "log.txt" in append mode and
appends the string "Error: File not found!" to it?
a) file = open("log.txt", "a")
file.write("Error: File not found!")
38
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
file.close()
Help Ravi to complete the task by filling blanks with appropriate code.
import pickle
def ________________ # statement 1
fobj = open(“_________”, “___”) # statement 2
num = 0
try:
while True:
rec=________.load(fobj) # statement 3
if _____ > 75: # statement 4
print(rec[0], rec[1], rec[2])
num = num +1
_______ : # statement 5
fobj.close()
return num
Statement1
39
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
Countrec():
Statement 2
“STUDENT.DAT” , “wb”
Statement 3:
fobj
Statement 4
rec[2]
Statement 5
except EOFError
2. Mr. Kulveer loves programming. He joined an institute for learning. He is learning python. He
learned all the python concepts like strings, lists, tuple , dictionaries etc. but he wants to learn file
handling in python. He is trying to learn binary file handling. His teacher gave him partial code to
write and read data from employee.dat having structure empno, name, salary. Help Kulveer to
complete the code:
___________________ # statement 1
def addrecords():
fw= _____________ #statement 2
dict={}
ch=‟y‟
while ch==‟y‟:
eno=int(input(“enter employee number”))
nm= input(“enter employee name”)
sal=int(input(“enter employee salary”))
dict={„empno‟:eno,‟name‟:nm,‟salary‟:sal}
____________________ # statement 3
ch=input(“add more record”)
fw.close()
# function to diplay records
def display():
dict={}
fr= _____________ # statement 4
dict=____________ # statement 5
fr.close()
print(“data :”,dict)
Help Kulveer to import the module to perform binary file operation in statement 1.
a) csv
b) random
c) pickle
d) file
Which statement is used from the following for statement 2 to open the binary file in write
mode?
a) open(“employee.dat”,‟w‟)
b) open(“employee.dat”,‟wb‟)
c) open(“employee.dat”,‟w+‟)
d) open(“employee.dat”,‟r‟)
Which statement is used from the following for statement 3 to write dictionary data created in
above code, namely dict, is written in binary file employee.dat file?
a) pickle.dump(dict,fw)
40
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
b) pickle.write(dict,fw)
c) pickle.save(dict,fw)
d) pickle.store(dict)
Which statement is used from the following for statement 4 to open the binary file in read
mode?
a) open(“employee.dat”,‟r‟)
b) open(“employee.dat”,‟r+‟)
c) open(“employee.dat”,‟a‟)
d) open(“employee.dat”,‟rb‟)
Compelete statement 5 to read data in dictionary namely dict from the opened binary file?
a) dict=pk.read(fr)
b) dict=pickle.load(fr)
c) pickle.load(dict,fr)
d) none of these
3. Mr. Kulveer has given the following code to modify the records of employees from employee.dat
used in above code. He has to increase Rs. 2000 in the salary of those who are getting less than
15000. Mr. Kulveer has to find the records and change the salary in place. His teacher gave him
partial code. Help him to complete the code.
import pickle as pk
found=False
emp={}
fin = ___________ #1 statement : open file both in read write mode
# read from file
try:
while true:
pos= _______ #2 store file pointer position before reading record
emp=_______ #3 to read the record in emp dictionary
if emp[„salary‟]<15000:
emp[„salary‟]+=10000
_________ #4 place file pointer at exact location of record
pickle.dump(emp,fin)
found=True
except EOFError:
if found==False:
print(“record not found”)
else:
print(“successfully updated”)
fin.close()
In #1 statement open the file in read and write mode. Which statement is used out of the
followings?
a) open(“employee.dat”,‟rb+‟)
b) open(“employee.dat”,‟r+‟)
c) open(“employee.dat”,‟a‟)
d) open(“employee.dat”,‟rb‟)
Choose the appropriate statement to complete #2 statement to store file pointer position before
reading record.
a) pk.seek(pos)
b) fin.tell()
c) pk.position()
41
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
d) pk.tell()
Choose the appropriate statement to complete #3 statement to read record in emp dictionary.
a) pk.read(fin)
b) pickle.load(fin,emp)
c) pk.dump(emp)
d) pk.load(fin)
Choose the appropriate statement to complete #4 statement to place file pointer at exact
location of record
a) fin.seek(pos)
b) pos=fin.seek()
c) fin.position()
d) none of the above
4. Ms. Seema is working on a binary file and wants to write data from a list to a binary file.
Consider list object as l1, binary file suman_list.dat, and file object as f.
(i) Which of the following can be the correct statement for her?
a) f = open(“suman_list”,”wb”); pickle.dump(l1,f)
b) f = open(“suman_list”,”rb”); l1=pickle.dump(f)
c) f = open(“suman_list”,”wb”); pickle.load(l1,f)
d) f = open(“suman_list”,”rb”); l1=pickle.load(f)
(ii ) Which option will be correct for reading file for seema?
a) f = open(„suman_list‟,‟rb‟)
b) f = open(„suman_list‟,‟r‟)
c) f = open(„suman_list‟,‟r+‟)
d) f = open(„suman_list‟,‟ab‟)
(iii) In which of the file mode existing data will be intact in binary file?
a) a
b) ab
c) w
d) wb
(iv ) Which one of the following is correct statement?
a) import – pickle
b) pickle import
c) import pickle
d) All of the above
(v) What are the binary files used for?
Incomplete Code :
42
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
Import ___________ # Statement 1
def createfile():
File=open(“d:\\Stock.dat”,‟____‟) #Statement 2
pno=input(“Enter product no:”)
pname= input(“Enter product name:”)
qty= input(“Enter product quantity:”)
price= input(“Enter product price:”)
record=[pno,pname,qty,price]
_______________ # Statement 3
Print(“Record inserted”)
File.close()
createfile()
(i) Identify the suitable code for blank space in line marked as Statement-1.
a) csv
b) CSV
c) pickle
d) PICKLE
(ii) Identify the suitable code for blank space in line marked as Statement-2.
a) wb
b) ab
c) w
d) a
(iii) select correct statement to write data into file for Statement-3.
a) pickle.dump(record,file)
b) pickle.dump(record)
c) pickle.dump(file,record)
d) pickle.load(record,file)
(iv) Which method is used for object deserialization ?
a) Pickling
b) Unpickling
c) All of the above
d) None of the above
(v)What is the last action that must be performed on a file?
a) save
b) close
c) end
d) write
43
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
BINARY FILES - CASE BASED QUESTIONS
QNO ANSWER
1.
Statement1
Countrec():
Statement 2
“STUDENT.DAT” , “wb”
Statement 3:
fobj
Statement 4
rec[2]
Statement 5
except EOFError
2.
i. C
ii. B
iii. A
iv. D
v. B
3.
i. A
ii. B
iii. D
iv. B
4.
i. A
ii. A
iii. B
iv. C
v. A
5.
i. C
ii. B
iii. A
iv. B
v. B
44
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
CSV FILE HANDLING – CASE BASED QUESTIONS
import mysql.connector
mydb=_______________(host="localhost",user="root",passwd='root',database="class12")
# statement 1
mycursor=mydb.cursor()
mycursor._____________("DELETE FROM EMPLOYEE WHERE EMPNO=114") #
statement 2
_______________ # statement 3
3. Mr. Rohan has written the given code in python that defines and calls the following user defined
functions.
Addrecord() – To add a student record to a CSV file Student.csv where each record contains a list
of field values ADMNO, NAME, CLASS ( reads values from keyboard)
Count() – To count the number of records present in file Student.csv
Help him to fill in the blanks to complete the program
import _____________ # statement 1
def Addrecord():
f=open("Student.csv","a",newline="")
wr= ______________ # statement 2
admno=int(input("Ente admission no: "))
name=input("Enter name :: ")
Class=int(input("Enter Class: "))
l=[admno,name,Class]
wr.
f.close()
def count():
f=open("Student.csv","r",newline="")
data=csv.reader(f)
d=list(data)
print(len(d))
f.close()
Addrecord()
count()
45
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
4. The program given below is to create a CSV file Employee.csv by suppressing EOL translation.
Each employee record contains a list of fields ENAME, DESIGNATION, SALARY
The writerows() method is adding 5 records to the file.
import csv
f=open( _____________ ) # statement 1
wr=csv. _____________ # statement 2
empdata=[["Rahul","Assistant",34000],
["Abhinav","Manager",67000],
["John","Clerk",23000],
["Vinod","Accountant",32000],
["Mahitha","Clerk",28000]]
wr.
f.close()
5. The code given below is searching and printing record in a file named “result10.csv”. each
record contains details in the order [rollno, name, result].
Fill in the blanks so that the program is correct and complete.
6 Rohit, a student of class 12th, is learning CSV File Module in Python. During examination, he
has been assigned an incomplete python code (shown below) to create a CSV File 'Student.csv'
(content shown below). Help him in completing the code which creates the desired CSV File.
CSV File
1,AKSHAY,XII,A
2,ABHISHEK,XII,A
3,ARVIND,XII,A
4,RAVI,XII,A
5,ASHISH,XII,A
Incomplete Code
import_____ #Statement-1
fh = open(_____, _____, newline='') #Statement-2
stuwriter = csv._____ #Statement-3
data = []
header = ['ROLL_NO', 'NAME', 'CLASS', 'SECTION']
data.append(header)
for i in range(5):
roll_no = int(input("Enter Roll Number : "))
name = input("Enter Name : ")
Class = input("Enter Class : ")
section = input("Enter Section : ")
rec = [_____] #Statement-4
data.append(rec)
stuwriter. _____ (data) #Statement-5
fh.close()
46
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
i) Identify the suitable code for blank space in line marked as Statement-1.
a) csv file b) CSV c) csv d) Csv
Answer : c) csv
ii) Identify the missing code for blank space in line marked as Statement-2?
a) "School.csv","w" b) "Student.csv","w" c) "Student.csv","r" d) "School.csv","r"
Answer : b) "Student.csv","w"
iii) Choose the function name (with argument) that should be used in the blank space of line
marked as Statement-3
a) reader(fh) b) reader(MyFile) c) writer(fh) d) writer(MyFile)
Answer : c) writer(fh)
iv) Identify the suitable code for blank space in line marked as Statement-4.
a) 'ROLL_NO', 'NAME', 'CLASS', 'SECTION' b) ROLL_NO, NAME, CLASS, SECTION
c) 'roll_no','name','Class','section' d) roll_no,name,Class,sectionc) co.connect()
Answer : d) roll_no,name,Class,section
v) Choose the function name that should be used in the blank space of line marked as Statement-5
to create the desired CSV File?
a) dump() b) load() c) writerows() d) writerow()
Answer : c) writerows()
__________________ #Statement-1
fn = open(_____, _____, newline='') #Statement-2
sdata = csv._____ #Statement-3
temp = [ ]
sid = int(input("Enter Student Id : "))
sname = input("Enter Student Name : ")
class = input("Enter Class : ")
record = [ _____ ] #Statement-4
temp.___________ (record) #Statement-5
sdata. dump ( ___________ ) #Statement-6
fn.close()
(a) writer(fn)
(b) reader(fn)
(c) readline(fn)
(d) writeline(fn)
(a) add
(b) writes
(c) append
(d) dump
(a) record
(b) temp
(c) fn
(d) csv
a. csv
b. CSV
c. cvs
d. csv file
Ans. a. csv
a. "book.csv", "r"
b. "book.csv", "w"
c. "book.csv file", "w"
d. "book", "w"
a. reader(fn)
b. read(book)
c. writer(fn)
d. write(fn)
Ans. c. writer(fn)
a. dump( )
b. close( )
c. exit( )
d. end( )
Ans. b. close( )
a. fn =
49
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
b. with
c. With
d. as
Ans. b. with
a. readlines(fn)
b. read(fn)
c. readrows()
d. reader(fn)
Ans. d. reader(fn)
9 Amit, a student of class 12th is trying to write a program to search the record from
“data.csv” according to the admission number input from the user. Structure of record saved
in “data.csv” is Adm_no, Name, Class, Section, Marks. He has written the partial code and
has missed out certain statements, You as an expert
of Python have to provide the answers of missing statements based on the following code of
Amit.
Ans.
a. CSV
b. Csv
c. Picke
d. csv
Ans. d. csv
a. "data.csv", "r"
b. "data.csv", "w"
50
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
c. "data.csv", "a"
d. "data.csv", "wb"
Ans. a. “data.csv”, “r”
a. Reader
b. reader( )
c. reader
d. read
Ans. c. reader
a. >
b. >=
c. ==
d. !=
Ans. c. ==
a. 0
b. 1
c. 2
d. 3
Ans. b. 1
a. if
b. else
c. elif
d. if-
Ans. b. else
51
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
CSV FILES - CASE BASED QUESTIONS
QNO ANSWER
1.
Statement 1:
mysql.connector
Statement 2:
mydb.cursor()
Statement 3:
mydb.commit()
2.
Statement 1:
mysql.connector.connect
Statement 2:
execute
Statement 3:
mydb.commit()
3.
Statement 1:
csv
Statement 2:
csv.writer(f)
Statement 3:
writerow(l)
4.
Statement 1:
"Employee.csv","w",newline=""
Statement 2:
writer(f)
Statement 3:
writerows(empdata)
5.
Statement 1:
csv
Statement 2:
csv.reader(f)
Statement 3:
csv_reader
52
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
DATABASE MANAGEMENT SYSTEMS - CASE STUDY QUESTIONS:
Q2) Write SQL commands for the queries (i) to (iv) based on the tables DRESS and MATERIAL.
DRESS
DCODE DESCRIPTION PRICE MCODE LAUNCHDATE
10001 FORMAL SHIRT 1250 M001 12–JAN–08
10020 FROCK 750 M004 09–SEP–07
10012 INFORMAL SHIRT 1450 M002 06–JUN–08
10019 EVENING GOWN 850 M003 06–JUN–08
10090 TULIP SKIRT 850 M002 31–MAR–07
10023 PENCIL SKIRT 1250 M003 19–DEC–08
10089 SLACKS 850 M003 20–OCT–08
10007 FORMAL PANT 1450 M001 09–MAR–08
10009 INFORMAL PANT 1400 M002 20–OCT–08
10024 BABY TOP 650 M003 07–APR–08
53
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
MATERIAL
MCODE TYPE
M001 TERELENE
M002 POLYESTER
M003 SILK
M004 COTTON
(i) To display DCODE and DESCRIPTION of an each dress in ascending order of DCODE.
(ii) To display the details of all the dresses which have LAUNCHDATE in between 05–
DEC–07 and 20–JUN–08 (inclusive of both the dates).
(iii) To display the average PRICE of all the dresses which are made up of material with MCODE
as M003.
(iv) To display material wise highest and lowest price of dresses from DRESS table.
(Display MCODE of each dress along with highest and lowest price)
Q3) Write the SQL command for the following on the basis of given table.
Table : SPORTS
i)Display the names of the students who have grade „A‟ in either Game 1 or Game 2 or both.
ii)Display the number of students having the GRADE1 as „A‟ in Game1.
iii)Display the names of students who have same game for both Game1 and Game2.
iv)Display the games taken by the students whose name starts with „A‟
v) Give the output of the following sql statements as per table given above.
i) SELECT COUNT(*) FROM SPORTS.
ii) SELECT DISTINCT Class FROM SPORTS.
iii) SELECT MAX(Class) FROM STUDENT;
vi) SELECT COUNT(*) FROM SPORTS GROUP BY Game1;
Q4) The given program is used to connect python with MySQL and show all the data present in the table
“stmaster” from the database “oraclenk”. You are required to complete the statements so that the code
can be executed properly.
import _____.connector __ pymysql #STATEMENT1
dbcon=pymysql._____________(host=”localhost”,user=”root”,________=”sia@1928”)
#STATEMENT2
if dbcon.isconnected()==False
print(“Error in establishing connection:”)
cur=dbcon.______________() #STATEMENT3
query=”select * from stmaster”
cur.execute(_________)#STATEMENT4
54
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
resultset=cur.fetchmany(3)
for row in resultset:
print(row)
dbcon.______() #STATEMENT5
Q5) Consider the following tables EMPLOYEE and DEPARTMENT and answer (a) and (b) parts of
this question.
TABLE: EMPLOYEE
TABLE :DEPARTMENT
i) To display all DepName along with the DepCde in descending order of DepCde.
ii) To display the average age of Employees in DepCde as 103.
iii) To display the name of DepHead of the Employee named “Sanjeev P”
iv) To display the details of all employees who has joined before 2007 from EMPLOYEE
table.
55
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
DATABASE MANAGEMENT SYSTEMS - CASE STUDY ANSWERS:
Q1) (i) select crec, cdate, city from courier order by amount desc;
(ii) Select count(cno) from courier where amount>200;
(iii) Select sum(amount) , city from courier group by city ;
(iv)
Cno Crec
245 Sam
940 Elizabeth
999 Nicolas
v)
Count(Cno)
3
(vi)
Max (amount) Min(amount)
325 100
Q2) (i) Select DCODE, DESCRIPTION from DRESS order by DCODE DESC
(ii) select * from DRESS where LAUNCHDATE >= 05–DEC–07 and LAUNCHDATE<=20–
JUN–08
(iii)Select avg(PRICE) from DRESS where MCODE=M003
(iv)select DESCRIPTION, PRICE, MCODE from DRESS order by PRICE DESC, MCODE ASC)
Q3) i) Select Name from SPORTS where Grade1=‟A‟ OR Grade2=‟A‟;
ii)Select count(*) from SPORTS group by GAME1 having GRADE1=‟A‟;
iii)Select Name from SPORTS where Game1=Game2;
iv)Select Game1,Game2 from SPORTS where Name LIKE „A%‟;
v) i)6
ii)4
iii)10
iv)2 2 1 1
Q4)
import mysql.connector as pymysql
dbcon=pymysql.connect(host=”localhost”, user=”root”, passwd=”sia@1928”)
if dbcon.isconnected()==False
print(“Error in establishing connection:”)
cur=dbcon.cursor()
query=”select * from stmaster”
cur.execute(query)
resultset=cur.fetchmany(3)
for row in resultset:
print(row)
dbcon.close()
56
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
Q5) (1)
03 Mar-2010 12-Jul-2004
iii)
TName DepHead
RaguvindraK | Rajiv
Kumar
CR Menon PK Singh
Sanjeev P Rajiv
Kumar
iv) 5
57
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
COMPUTER NETWORKS - CASE BASED QUESTIONS:
Q
Innovation Hub India is a knowledge community aimed to uplift the standard of skills
1.
and knowledge in the society. It is planning to setup its training centres in multiple
towns and villages of India with its head offices in the nearest cities. They have created
a model of their network with a city, a town and 3 villages as given.
As a network consultant, you have to suggest the best network related solution for
their issues/problems raised in (i) to (v) keeping in mind the distance between
various locations and given parameters.
Note:
* In Villages, there are community centres, in which one room has been given as a training center
to this organization to install computers.
* The organization has got financial support from the government and top IT companies.
i.Suggest the most appropriate location of the SERVER in the YHUB (out of the 4 locations), to
get the best and effective connectivity. Justify your answer.
58
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
ii. Suggest the best wired medium and draw the cable layout (location to location) to efficiently
connect various locations within the YHUB.
iii. Which hardware device will you suggest to connect all the computers within each location of
YHUB?
iv. Which server/protocol will be most helpful to conduct live interaction of Experts from Head
office and people at YHUB locations?
v. Suggest a device/software and its placement that would provide data security for the entire
network of the YHUB.
Q Shyamji Marketing Ltd. has four branches in its campus named Udaipur, Kota, Jodhpur and Ajmer.
2. Shyamji Marketing Ltd. wants to establish the networking between all the four offices. A rough
layout of the same is as follows:
Udaipur
Jodhpur Office
Office
Kota
Ajmer Office
Office
Approximate distances between these offices as per network survey team are as follows:
In continuation of the above, the company experts have planned to install the
following number of computers in each of their offices:
Udaipur 40
Jodhpur 80
Kota 200
Ajmer 60
i. Suggest the most suitable place (i.e., Block/Centre) to install the server of this organization
59
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
with a suitable reason.
ii. Suggest an ideal layout for connecting these blocks/centre for a wired connectivity.
iii. Which device will you suggest to be placed/installed in each of these offices to efficiently
connect all the computers within these offices?
v. The organization is planning to connect its new office in Delhi, which is more than 1250 km
current location. Which type of network out of LAN, MAN, or WAN will be formed? Justify
your answer.
Block Computers
Conference 25
Finance 60
i. What will be the most appropriate block where organization should plan to install their server?
ii.Draw a block-to-block cable layout to connect all the buildings in the most appropriate manner
for efficient communication.
60
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
iii.What will be the best possible connectivity out of the following to connect the new set-up of
offices in Nagpur with its London base office?
(i) Co-axial cable (ii) Satellite Link (iii) Ethernet Cable
iv.Which of the following devices will you suggest to connect each computerin each of the above
buildings?
(i)Gateway (ii) Switch (iii) Modem
v.Write names of any two popular OpenSource Software which are used asOperating Systems.
4. WeLearn University is setting up its academic blocks at Raipur and is planning to set
up a network. The University has 3 academic blocks and one Human Resource Centre
as shown in the diagram below:
Law Block 15
Technology Block 40
HR centre 115
Business Block 25
i. Suggest the most suitable place (i.e., Block/Centre) to install the server of this University with
a suitable reason.
ii. Suggest an ideal layout for connecting these blocks/centre for a wired connectivity.
61
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
iii. Which device will you suggest to be placed/installed in each of these blocks/centre to
efficiently connect all the computers within these blocks/centre
v. The university is planning to connect its admission office in Delhi, which is more than 1250km
from university. Which type of network out of LAN, MAN, or WAN will be formed? Justify
your answer
5. Hindustan Connecting World Association is planning to start their offices in four major cities
inIndiatoprovideregionalITinfrastructuresupportinthefieldofEducation&Culture.Thecompany has
planned to set up their head office in New Delhi in three locations and have namedtheir New Delhi
offices as “Sales Office” , “Head Office” and “Tech Office”.
The company‟s regionaloffices are located at “Coimbatore”, “Kolkata” and “Ahmedabad”. A rough
layout of the same is asfollows:
Approximatedistancebetweentheseofficesaspernetworksurveyteamisasfollows:
In
continuationoftheabove,thecompanyexpertshaveplannedtoinstallthefollowingnumberofcomputersin
eachoftheiroffices:
HeadOffice 100
SalesOffice 20
TechOffice 50
KolkataOffice 50
AhmadabadOffice 50
CoimbatoreOffice 50
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 Coimbatore Office
ii)Which device you will suggest to be produced by the company for connecting all the computers
with in each of their offices out of the following devices?
a. Modem
b. Telephone
62
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
c. Switch/Hub
iii)Which of the following communication media, will suggest to be procured by the company for
connecting their local offices in New Delhi for very effective and fast communication?
a. Ethernet Cable
b. Optical Fibre
c. Telephone Cable
iv)Suggest a cable/writing layout for connecting the company‟s local offices located in New Delhi.
v) Suggest the most suitable place (i.e., Block/Office) to install the server of this Company with a
suitable reason.
1. i) YTOWN
Justification:-Since it has the maximum number of computers.
ii) Optical Fiber
Layout:
3. i) Human Resource
ii)
63
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD
iii) Satellite Link
iv) Switch
v) Linux, Ubuntu, Open Solaris or any other Open Source O/s
4. i) Most suitable place to install the server is HR center, as this center has
maximumnumber of computers
ii)
v) WAN, as the given distance is more than the range of LAN and MAN.
5. i) a. The type of network between the Head Office and Tech Office is LAN
(Local Area Network).
b.The type of network between the Head Office andCoimbatore Office is WAN
(Wide Area Network).
ii)c. The suitable device for connecting all the computers in each of their offices is
switch/hub.
iii)b.Optical Fibre
iv)The suggested layout for connection is as follows:
v) Head Office
64
CLASS 12 COMPUTER SCIENCE SUPPORT MATERIAL 2023-24 KVS RO HYDERABAD