Xii CS QB 2024-25
Xii CS QB 2024-25
Database
3
Management Database Management
Content Coordinators
Shri Rajesh Sahu, Principal
PMSHRI Kendriya Vidyalaya Hoshangabad
Content Creators
Name of K.V. Name of P.G.T. (Comp. Sc.)
Tikamgarh Mrs. Monika Verma
IIT Indore Mr. Deepak Bhinde
Mungaoli Mr. Vijendra Rathore
Indore No. 1(Shift I) Mr. Kamal Kishore Sharma
Itarsi CPE Mrs. Hemlata Soni
Itarsi OF Mr. Vikas Mehsram
No. 1 Bhopal Mr. Manoj Kumar Verma
No. 5 Gwalior Mr. Mohan Dixit
No. 1 Gwalior (Sh 1) Mrs. Varsha Saxena
No. 1 Gwalior (Sh 2) Mr. Vinayak Soni
Jhabua Mr. Vinay Kumar Kaushik
Morena Mr. Hansraj Saini
ITBP Shivpuri Mr. Abhishek Arya
Bhind Mr. Mahendra Pratap Singh
Rajgarh Mr. Rajesh Kumar Meena
Sarni Mr. Manoj Kumar Ahirwar
Cover Page Design
No.3 Gwalior Mrs Sangeeta M Chauhan
Data Structure
35
Computer
2 Computer Networks
Networks 40
Database
3
Management Database Management 70
PYTHON REVISION TOUR CLASS XI
Topic Tokens Ma
Description: Smallest individual unit of a program is called token rks
Example : Variable, Literal, Keyword etc.
Q.1 How many tokens are in the following code: 1
c = a+b
Ans: Tokens : c, =, a, +, b
Q.2 Write the type of tokens from the following 1
(i) If (ii) roll_no
Ans: (i) Keyword, (ii) Variable
Topic Keyword : Any reserved word in Python.
a=5
where a is a variable.
Q.4 Which one is legal variable : 1
a. _abc, b. 1sa, c. ss dd, d. si@32
Ans: a. _abc
Topic Conditional Statements:
Statements that are used to define conditions.
i=1
while i<=5:
print(i)
i = i+1
This code is displaying natural number from 1 to 5 using while loop.
Example: Integer: 1, 40
Float : 2.5
pg. 2
String : “Hello”
Boolean : True, False
Q.13 Write the datatype of following literals: 2
(i) 50.7 (ii) “India”
Q2. Write a function countNow(PLACES) in Python, that takes the dictionary PLACES as an
argument and displays the names (in uppercase) of the places whose names are longer than
5 characters.
For example, Consider the following dictionary
PLACES={1:"Delhi",2:"London",3:"Paris",4:"New York",5:"Doha"}
The output should be:
LONDON
NEW YORK
Q3. Write a function EVEN_LIST(L), where L is the list of elements passed as argument to the
function. The function returns another list named ‘evenList’ that stores the indices of all
even numbers of L.
For example: If L contains [12,4,3,11,13,56] The evenList will have - [0,1,5]
Q4. 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 ‘fourCharList’ that
stores the all four lettered word of L.
For example: If L contains [“DINESH”, “RAMESH”, “AMAN”, “SURESH”, “KARN”]
The indexList will have [“AMAN”, “KARN”]
Q5. Write a function countVowel() in Python, which should read each character of a text file
“myfile.txt” and then count and display the count of occurrence of vowels (including small
cases)
Q7. Write a function COUNTWORDS( ) in python to display the count of words starting with
“T” or “S” in a text taken from the user
Q8. Write a function COUNTS( ) in Python to read the text file “ABC.TXT” and count the
number of times the word “THE” occurs in the file. (Case insensitive the)
Q9. Write a function modilst(L) that accepts a list of numbers as argument and increases the
value of the elements by 10 if the elements are divisible by 5. Also write a proper call
statement for the function.
pg. 6
For example: If list L contains [3,5,10,12,15]
Then the modilist() should make the list L as [3,15,20,12,25]
Q10.
Predict the output of the following code:
def Changer(P,Q=10) :
P=P/Q
Q=P%Q
return P
A=200
B=20
A=Changer(A,B)
print(A,B, sep='$')
B=Changer(B)
print(A,B, sep='$', end='###')
Q11. Write a function SQUARE_LIST(L), where L is the list of elements passed as argument to
the function. The function returns another list named ‘SList’ that stores the Squares of all
Non-Zero Elements of L.
For example:
If L contains [9,4,0,11,0,6,0]
The SList will have - [81,16,121,6]
Q13. The code given below accepts a number as an argument and returns the reverse
number. Observe the following code carefully and rewrite it after removing all syntax and
logical errors. Underline all the corrections made.
define revNumber(num):
rev = 0
rem = 0
While num > 0:
rem ==nurn %10
rev = rev* 10 4- rem
num = num//10
return rev
print(revNumber(1234))
15 Questions Assertion and Reasoning
ASSERTION (A) and REASONING (R) based questions. Chose the correct choice as your
answer
(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.
pg. 7
Assertion (A):- The default value of an argument will be used inside a function if we do not
pass a value to that argument at the time of the function call.
Reasoning (R):- the default arguments are optional during the function call. It overrides the
default value if we provide a value to the default arguments during function calls.
2.
Assertion (A):- To use a function from a particular module, we need to import the module.
Reasoning (R):- Import statement can be written anywhere in the program, before using a
function from that module.
3.
Assertion (A):- If the arguments in a function call statement match the number and order of
arguments as defined in the function definition, such arguments are called positional
arguments.
Reasoning (R):- During a function call, the argument list first contains default argument(s)
followed by positional argument(s).
4.
Assertion (A):- Local Variables are accessible only within a function or block in which it is
declared.
Reasoning (R):- Global variables are accessible in the whole program
5.
Assertion (A):- The default arguments can be skipped in the function call.
Reasoning (R):- The function argument will take the default values even if the values are
supplied in the function call
6.
Assertion (A):- Built in function are predefined in the language that are used directly.
Reasoning (R):- print () and input () are built in functions
7.
Assertion (A):- Key word arguments are related to the function calls.
Reasoning (R):- When you use keyword arguments in a function call, the caller identifies the
arguments by the parameter name.
8.
Assertion (A):- A function is a block of organized and reusable code that is used to perform a
single, related action.
Reasoning (R):- Function provide better modular form to application and a high degree of
code reusability
9.
Assertion (A):- Assertion. A function is a subprogram.
Reasoning (R):- A function exists within a program and works within it when called.
Assertion (A):- During a function call, the argument list first contains default argument(s)
followed by positional argument(s).
Reasoning (R):- Inside a function, we can declare local as well as global arguments.
10.
Assertion (A):- Non-default arguments cannot follow default arguments in a function call.
Reasoning (R):- A function call can have different types of arguments.
11.
Assertion (A):- A function declaring a variable having the same name as a global variable,
cannot use that global variable.
Reasoning (R):- A local variable having the same name as a global variable hides the global
variable in its function.
12.
Assertion (A):- A variable declared inside a function cannot be used outside it.
pg. 8
Reasoning (R):- A variable created inside a function has a function scope.
13.
Assertion (A):- A variable not declared inside a function can still be used inside the function
if it is declared at a higher scope level.
Reasoning (R):- Python resolves a name using LEGB rule where it checks in Local (L),
Enclosing (E), Global (G) and Built-in scopes (B), in the given order.
Answer: c
(2.)
a) Hello World!
Hello World!
b) ‘Hello World!’
‘ Hello World!’
c) Hello
Hello
d) None of the mentioned
Answer: a
(3.) What is the output of the below program?
pg. 9
a)
x is 50
Changed global x to 35
Value of x is 50
b) x is 50
Changed global x to 2
Value of x is 2
c)
x is 50
Changed global x to 50
Value of x is 50
Answer: b
Answer: d
Answer : d
pg. 10
Answer : gMAILabcCOM
(8.)What may be the output of the program given below –
a)0 : 0
b)2 : 4
c)1 : 2
d)0 : 5
Answer : a
a)Only (i)
b)(i) and (ii)
c)(iii) and (iv)
d)(i), (iii) and (iv)
Answer : d
a) 50 b) 0 c) Null d) None
Answer : d
pg. 11
(11.)What will be the output of the following code :
a)100 200
b)150 300
c)250 75
d)250 300
Answer : d
a)50#50
b)5#5
c)50#30
d)5#50#
Answer : b
a)5#8#15#4#
b)5#8#5#4#
pg. 12
c)5#8#15#14#
d)5#18#15#4#
Answer : b
(14.)What will be the output of the following code :
a)3 3 3
b)3 4 5
c)5 5 5
d)3 5 5
Answer : c
Answer : c
(16.)What is the scope of a variable declared in top level segment (– main –) of a program ?
a)Global
b)Local
c)Depends on its used
d)None of these.
Answer : a
Answer : d
(18.)
...................... are the variables that are listed within parentheses of a function header.
a)Parameters
b)Arguments
c)Values
d)None of these
Answer : a
Answer :b
(20.)When the function call statement must match the number and order of arguments as
defined in the function definition, this is called the ....................... .
a)Default parameters
b)Positional argument
c)Formal parameters
d)Actual parameters
Answer : b
FUNCTION
Working with Functions MLL
Q.1)Define a function?
Ans: - It is a sub program that perform some task on the data and return a value.
return (X*Y)
Q.3)Write a python function that takes two numbers and print the smaller
number. Also write how to call this function.
if(A<B):
print(“Smaller No – “, A)
else:
pg. 14
print(“Smaller No – “, B)
a=int(input(“Enter a number:”))
b=int(input(“Enter
another umber:”))
SMALLER(a,b)
one values.
def square_and_cube(X):
a=3
x,y,z=sq
uare_an
d_cube()
print(x,y
Ans: - Part of program within which a name is legal and accessible is called scope of the
variable.
Ans – Global Scope – A name declared in top level segment of a program is said to
have global scope and it is accessible inside whole programme.
Local Scope – A name declared in a function body is said to have local scope and it
can be used only within this function.
Q8. Define a Python function count_vowels(s) that counts and returns the number of vowels
in a given string s. Consider both uppercase and lowercase vowels. Provide the function
definition and an example of its usage.
def count_vowels(s):
""" Function to count the number of vowels in a given string. """
vowels = "aeiouAEIOU"
count = 0
for char in s:
if char in vowels:
count += 1
return count
# Example usage
string = "Python Programming"
print("Number of vowels in the string:", count_vowels(string))
Q9. Write a Python function calculate_fibonacci(n) that calculates and returns the nth
Fibonacci number using iteration (loop). Provide the function definition and an example of
its usage.
def calculate_fibonacci(n):
""" Function to calculate the nth Fibonacci number using iteration (loop). """
if n <= 1:
return n
else:
a, b = 0, 1
pg. 16
for _ in range(2, n + 1):
a, b = b, a + b
return b
Q10. Write a Python function calculate_factorial(n) that calculates the factorial of a non-
negative integer n using recursion. Provide the function definition and an example of its
usage.
def calculate_factorial(n):
"""Function to calculate the factorial of a non-negative integer using recursion. """
if n == 0 or n == 1:
return 1
else:
return n * calculate_factorial(n - 1)
# Example usage
number = 5
print("Factorial of", number, "is:", calculate_factorial(number))
pg. 17
# Example usage
number = 23
if check_prime(number):
print(number, "is a prime number.")
else:
print(number, "is not a prime number.")
MCQ FUNCTION
1. Lalit is a game programmer and he is designing a game where he has to use different
python functions as much as possible. Apart from other things, following functionalities are
to be implemented in the game.
Lalit is feeling difficulty in implementing the above functionalities. Help him by giving
answers following questions:
Ans: b) randomise
Ans: (c)
2. One student who is learning Python, is making a function-based program to find the roots
of a quadratic equation. He wrote the program but he is getting some error. Help him to
complete the task successfully:
a) Two return statements are used and a function can use only one return statement
b) Required module is not given
c) Syntax error in line 4
d) Error in line 11
def function1(a):
a = a + '1'
a=a*2
Answer
a) indentation error
Reason — The line a = a * 2 should be indented backwards otherwise it will give an error.
ii) Write the statement that will call the above function:
a) function1()
b) function1(25,30)
c) function1(a=10)
d) function1(30,)
Answer
c) function1(a=10)
Reason — The function can call with single argument otherwise it will give an error.
pg. 19
4. Observe the following code and the answer of following questions:
def print_double(x=5):
print(2 ** x)
print_double() Statement 1
print_double(3) Statement 2
Answer
a) 32
Reason — The code defines a function named print_double that takes one parameter x. Inside
the function, it calculates 2 raised to the power of x using the exponentiation operator **,
and then prints the result. So, when we call print_double(), we're not passing any argument
to the function then it will take default argument that is 5. The function calculates 2 ** 5,
which is 32, and prints the result.
ii) Which of the given argument types can be skipped from a function call?
a) positional arguments
b) keyword arguments
c) named arguments
d) default arguments
Answer
d) default arguments
Reason — A default argument is an argument with a default value in the function header,
making it optional in the function call. The function call may or may not have a value for it.
5. Observe the following code and give the suitable the answer for following questions:
def person(name, age, city):
print(name, "is", age, "years old and lives in", city)
Answer:
a) Bob is 30 years old and lives in London
pg. 20
Reason — Keyword arguments allow us to specify arguments by their parameter names
during a function call, irrespective of their position.
ii) In the above code which type of argument used during function call:
a) Default Argument
b) Keyword Argument
c) Positional Argument
d) None of these
Answer:
b) Keyword Argument
Reason — Keyword arguments allow us to specify arguments by their parameter names
during a function call, irrespective of their position.
6. Ravish write down the following code in Python. But he is confused in Built in function
and User Defined function help him to find out built-in functions and user defined functions.
Answer:
Built-in functions — These are pre-defined functions and are always available for use. For
example:
In the above example, print(), len(), input() etc. are built-in functions.
7. Raman written the following code. Observe the following code and answer the following
question:
total = 0
def sum(arg1, arg2):
total = arg1 + arg2
print("Total :", total)
return total
sum(10, 20)
print("Total :", total)
pg. 21
i) Write the function with default argument for argument 2 and set the value is 10.
Answer:
total = 0
def sum(arg1, arg2=10):
total = arg1 + arg2
print("Total :", total)
return total
sum(10, 20)
print("Total :", total)
Reason —
There should be a colon (:) at the end of the function definition line to indicate the start of
the function block.
Python's built-in function for generating sequences is range(), not Range().
Python keywords like return should be in lowercase.
When calling a function in python, the arguments passed to the function should be enclosed
inside parentheses () not square brackets [].
Answer:
6
pg. 22
21
9. Consider the following code line numbers have been given for your reference.
Answer:
The flow of execution for the above program is as follows:
1 → 5 → 9 → 10 → 5 → 6 → 1 → 2 → 3 → 6 → 7 → 10 → 11
Explanation
Line 1 is executed and determined that it is a function header, so entire function-body (i.e.,
lines 2 and 3) is ignored. Line 5 is executed and determined that it is a function header, so
entire function-body (i.e., lines 6 and 7) is ignored. Lines 9 and 10 are executed, line 10 has a
function call, so control jumps to function header (line 5) and then to first line of function-
body, i.e., line 6, it has a function call, so control jumps to function header (line 1) and then
to first line of function-body, i.e, line 2. Function returns after line 3 to line 6 and then returns
after line 7 to line containing function call statement i.e, line 10 and then to line 11.
ii) What will be the output if it takes n=8.
Answer:
64
10. Consider the code below and answer the questions that follow :
Answer
5 times 5 = 25
Answer
pg. 23
After the code is executed, the variable output is equal to 25. This is because the function
multiply returns the result of multiplying 5 and 5, which is then assigned to the variable
output.
Answer: d
Explanation: There has to be at least one except statement.
Answer: c
Explanation: The else part is executed when no exception occurs.
Answer: a
Explanation: Each type of exception can be specified directly. There is no need to put it in a
list.
Answer: d
Explanation: The finally block is always executed.
pg. 24
finally:
return 2
k = foo()
print(k)
a) 1
b) 2
c) 3
d) error, there is more than one return statement in a single try-finally block
Answer: b
Explanation: The finally block is executed even there is a return statement in the try block.
Answer: a
Explanation: No error occurs in the try block so 1 is printed. Then the finally block is
executed and 2 is printed.
Answer: c
Explanation: The keywords ‘try’, ‘except’ and ‘finally’ are exception handling keywords in
python whereas the word ‘accept’ is not a keyword at all.
8. What will be the output of the following Python code if the input entered is 6?
valid = False
while not valid:
try:
n=int(input("Enter a number"))
while n%2==0:
print("Bye")
valid = True
except ValueError:
pg. 25
print("Invalid")
a) Bye (printed once)
b) No output
c) Invalid (printed once)
d) Bye (printed infinite number of times)
Answer: d
Explanation: The code shown above results in the word “Bye” being printed infinite number
of times. This is because an even number has been given as input. If an odd number had
been given as input, then there would have been no output.
Answer: a
Explanation: When any exception is thrown in try block, except block is executed. If
exception in not thrown in try block, else block is executed. When there is a deviation from
the rules of a programming language, a syntax error is thrown. The only true statement
above is: The standard exceptions are automatically imported into Python programs.
Answer: a
Explanation: An exception is an object that is raised by a function signaling that an unexpected
situation has occurred, that the function itself cannot handle.
EXCEPTION HANDLING
5 Questions MCQ (Exception Handling)
Q.1 Which keyword is used to force an exception ? 1
a. try, (b) except, (c) raise, (d) finally
Ans: a. try
Q.2 Error raised when an I/O operation fails for an I/O operations. 1
a. Name Error, (b) EOF Error, (c) IO Error, (d) Value Error
Ans: (c) IO Error
Q.3 Which of the following keywords are not specific to exception handling? 1
a. try, (b) except, (c)finally, (d) else
Ans: (d) else
Q.4 Which one is not example of exception: 1
pg. 26
a. Divide by zero, (b) Invalid Input, (c) Opening a non existing file,
(d) print string “hello” using print(“hello”)
Ans: (d) print string “hello” using print(“hello”)
Q.5 An unexpected error that occurs during runtime. 1
a. Exception, (b) try, (c) catch, (d) stack trace
Ans: a. Exception
Assertions/Reasons Ans:-
1. (a) 2(c) 3. (a) 4. (a) 5. (a) 6 (a) 7. (c) 8 (d) 9. (b) 10. (b)
pg. 27
Q1 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.
Q2 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.
Q3 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.
Q4
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.
Q5 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.
pg. 28
You need to read the contents of a text file into a list in Python, excluding any empty lines.
Which approach should you take?
A) Read the file using `file.read()` and then remove empty lines using a loop.
B) Use the `file.readlines()` method to read the file into a list and remove empty lines using a
loop.
C) Use the `file.read().splitlines()` method to read the file into a list, which automatically
excludes empty lines.
D) Read the file using `file.read()` and then use the `filter()` function to remove empty lines
from the resulting list.
Q7 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?
A) Use the `file.read()` method to read the entire file and then iterate over the lines.
B) Use the `file.readlines()` method to read all the lines at once and then iterate over them.
C) Iterate over the file object directly without using any specific method for reading the lines.
D) Use the `file.readline()` method inside a loop to read and process each line sequentially.
Q8 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?
A) Use the `file.write()` method to write each string, followed by a line break character.
B) Concatenate the strings into a single string with line break characters and then use the
`file.write()` method.
C) Use the `file.writelines()` method, passing the list of strings as an argument, without any
additional characters.
D) Iterate over the list of strings and use the `file.write()` method for each string, followed by
a line break character.
Q9 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)
Q10 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!")
file.close()
b) file = open("log.txt", "w")
pg. 29
file.write("Error: File not found!")
file.close()
c) file = open("log.txt", "r")
file.write("Error: File not found!")
file.close()
d) file = open("log.txt", "append")
file.write("Error: File not found!")
file.close()
ANSWER
1. A 2.A 3.A 4.A 5.A 6.C 7.C 8.C 9.B 10.A
Exception Handling MCQ
1. Vikas type the following code. What will happen if he executes the following code.
try:
print(x)
except:
print("An exception has occurred!")
2. Manish write the following code of Python. What will be the output, if he executes the
following code?
try:
print(1/0)
except ZeroDivisionError:
print("You cannot divide a value with zero")
except:
print("Something else went wrong")
Answer b)
Explanation: The code will output “Divide by zero error” because a ZeroDivisionError
exception is raised
Answer: b
Explanation: The finally block is always executed, regardless of whether an exception is raised
or caught.
Answer: b
Explanation: If the input is successfully converted to an integer, it will print “You entered:
<number>”. Otherwise, it will print “Invalid input”.
Answer: b
Explanation: The code will output “IndexError” because an IndexError exception is raised and
caught.
Answer: c
Explanation: The raise statement is used to explicitly raise exceptions in Python.
7. What will happen if an exception is raised but not caught in a Python program?
a) The program will continue executing normally
b) The program will terminate with an error message
c) The program will pause and wait for user input
d) The program will enter an infinite loop
Answer: b
Explanation: If an exception is raised but not caught, the program will terminate with an error
message
Answer: c
Explanation: The except keyword is used to catch all exceptions in Python.
9. Which of the following is true about the else block in Python exception handling?
a) The else block is executed if an exception occurs
b) The else block is always executed after the except block
c) The else block is executed if no exceptions occur in the try block
d) The else block is optional in exception handling
Answer: c
Explanation: The else block is executed if no exceptions occur in the try block.
Answer: a
Explanation: The code asks the user to enter two numbers, divides them, and prints the result.
It also handles exceptions for invalid input and zero division.
14. if file contains "Guido van Rossum is a Dutch programmer best known as the
creator of the Python programming language" then what will be the output of this
program?*
a. 100
b. 101
c. 102
d. 3
19. Nayana want to write 567 records in the file. If she want to store data in file ,( in
parts) on different working days then which mode must be used.*
a. w
b. r
c. a
d. wr
a. It will open binary file in write mode and write list in file after converting byte_arr into
binary
b. It will open binary file in write as well as read mode and write list in file after
converting byte_arr into binary
c. After writing byte_array (list) in binary format, file pointer is sent at beginning to read
the file content
d. At the time of reading content we are converting binary data into list data type
pg. 34
21.What is/are not true about the following code*
a. Pickling is the process of converting a Python object into a byte stream to store it in
a file/database
b. pickle.dump() method is used to read data from file
c. pickle.dump() method is used to write data into the binary file
d. We can only Write (can not read from file) into the file using pickle module
DATA STRUCTURE
DATA STRUCTURE ASSERTION AND REASONING
Directions 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
pg. 35
(c)A is true but R is False.
(d)A is False but R is true
1 Assertion(A)-A Stack is a LIFO structure.
Reasoning (R)-Any new element pushed into the stack always gets positioned at the
index after the last existing element in the stack.
Ans: - (a)
2 Assertion(A)-A Stack is a linear list implemented in Last in First Out manner.
Reasoning (R)-Insertion and deletions are restricted to occur only at one end-Stack’s
top
Ans: - (a)
3 Assertion(A): -Insertion in the Stack is known as PUSH operation.
Reasoning(R): -When one tries to push an item in stack that is full, Overflow occurs.
Ans: - (b)
4 Assertion(A): -POP operation removes item from Top of the Stack.
Reasoning(R): -Underflow refers to situation when one tries to delete an item from an
empty stack.
Ans: - (b)
5 Assertion(A): -LIFO stands for Last in First Out.
Reasoning(R): -An element may be inserted at both ends of the Stack.
Ans: - (c)
6 Assertion(A): - A Stack is a linear structure where insertions and deletions take place
only at one end i.e. the stack’s top
Reasoning(R): - A Stack is a FIFO Structure.
Ans: - (c)
7 Assertion(A): -A Stack allows insertion and deletion of element at both the ends
Reasoning(R): Stack is a LIFO Data Structure.
Ans: - (d)
8 Assertion(A):- When someone attempt to delete an item from empty stack Overflow
occurs,
Reasoning(R): An item is allowed to be deleted only from the Top of the Stack
Ans: - (d)
9 Assertion(A): -In Python, a Stack is implemented through Lists.
Reasoning(R): Append () method of list is used for PUSH operation
Ans: -(b)
10 Assertion(A): -Program should check for Overflow condition before executing PUSH
operation on Stack and similarly check for Underflow before executing POP operation.
Reasoning(R): In Stack Underflow, means there is no element available in the stack,
while overflow means no further element can be pushed into Stack.
Ans: -(a)
pg. 36
2. Assertion (A): A data structure is a named group of data types.
Reason(R): A data structure has a well-defined operations, behavior and properties.
3. Assertion (A): LIFO is a technique to access data from queues.
Reason(R): LIFO stands for Last In First Out.
4. Assertion (A): A Stack is a Linear Data Structure that stores the elements in FIFO order.
Reason(R): New element is added at one end and element is removed from that end only.
5 Assertion (A): An error occurs when one tries to delete an element from an empty stack.
Reason(R): This situation is called an Inspection.
6. Assertion (A): A stack is a LIFO structure.
Reason(R): Any new element pushed into the stack always gets positioned at the index after
the
last existing element in the stack.
7. Assertion (A): In stack, program should check for Underflow condition, before executing
the
pop operation.
Reason(R): In stack, underflow mean there is no element available in the stack or stack is an
empty stack.
8. Assertion (A): Program should check for overflow condition, before executing push
operation on stack and similarly check for underflow before executive pop operation.
Reason(R): In stack underflow, means there is no element available in the stack, while
overflow means no further element can be pushed into stack.
9. Assertion (A): Stake is a linear data structure that works on the principle of FIFO (First in
First Out).
Reason(R): The stake is created with the help of a list with some restrictions. it manages a
pointer called Stack Pointer (SP) that will increase or decrease by 1, if an element is entered
or removed from the stack respectively.
10. Assertion (A): The element in Stack is removed from the top.
Reason(R): The process of removal is called POP
MCQ (Data Structure)
pg. 37
9. Pushing an element into stack already having five elements and stack ha fixed size of
5., then ---------- occurs.
a. Overflow b) Crash c) Underflow d) User flow
10. When a stack is empty and an element’s deletion is tried from the stack, it is called
an ---------------.
a. Overflow b) Underflow c) Extraflow d) Noflow
Ans:-
1. a and c 2) a 3) a 4) c 5) b 6) b 7) a 8) d 9) a 10) b
(2.)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
pg. 38
d. FILO
8 12 17 19 25 28 33 32 56 90
(8.)Write a function Sum7End(MYLIST), which display only those items from the list which
ends from the digit 7, also find total of these elements.
For e.g. if MYLIST = [10,27,15,107,97,5,7,81,47]
The output should be
27
107
97
7
47
Total = 285
pg. 39
(10.)A dictionary contains the names of some cities and their population in crore. Write a
python function push(stack, data), that accepts an empty list, which is the stack and data,
which is the dictionary and pushes the names of those countries onto the stack whose
population is greater than 25 crores.
For example :
The data is having the contents {'India':140, 'USA':50, 'Russia':25, 'Japan':10} then the
execution of the function push() should push India and USA on the stack.
Solutions MLL
(1.)
status=[]
def Push_element(cust):
if cust[2]=="Goa":
L1=[cust[0],cust[1]]
status.append(L1)
(2.) stackItem=[]
def Push(SItem):
count=0
for k in SItem:
if (SItem[k]>=75):
stackItem.append(k)
count=count+1
print("The count of elements in the stack is : ", count)
(3.) b. LIFO
(4.) a. FIFO
(5.)
(i) [10,20,30,40,70]
(ii) [10,20,30,40,70,100]
(iii) [10,20,30,40,70]
(iv) 70
(6.)
(i) print(len(MYLIST))
(ii) print(MYLIST.count(30))
(iii) import bisect
bisect.insort(MYLIST,45)
print(MYLIST)
(iv) MYLIST.remove(17)
pg. 40
print(MYLIST)
(7.)
def CountEvenOdd(MYLIST):
counte=0
counto=0
for i in range(len(MYLIST)):
if MYLIST[i]%2==0:
counte+=1
else:
counto+=1
print("Even Count = ",counte)
print("Odd Count = ",counto)
(8.)
def Sum7End(MYLIST):
sum=0
for i in range(len(MYLIST)):
if MYLIST[i]%10==7:
print(MYLIST[i])
sum+=MYLIST[i]
print('Total=',sum)
(9.)
def Push(Employee):
name=input('Enter Employee name ')
Employee.append(name)
def Pop(Employee):
if len(Employee)==0: # or if Employee==[]:
print('Underflow')
else:
name = Employee.pop()
print('Popped Name was ',name)
(10.)
data={'India':140, 'USA':50, 'Russia':25, 'Japan':10}
stack=[]
def push(stack, data):
for x in data:
if data[x]>25:
stack.append(x)
push(stack, data)
print(stack)
COMPUTER NETWORKS
ASSERTION & REASONING
In the following questions, a statement of assertions (A) is followed by a statement of Reason (R).
Make the correct choice as
(a) Both A and R are true and R is the correct explanation of A
pg. 41
(b) Both A and R are true and but R is not the correct explanation of A
(c) A is true, but R is false, or partly true
(d) A is false or partly true, but B is true
(e) Both A and R are falls or not fully true
1. Assertion: The twisted pair cable is most commonly used wiring in LANs
Reason: Because of high attenuation, it is incapable of carrying signals over long distance without
repeater.
Answer: b
5. Assertion: A modem is a communication device that works on the principle of converting digital
data to analog and vice versa.
Reason: Modulation is a process of converting digital data to analog form and Demodulation is a
process of converting analog data to digital.
Answer: a
pg. 42
Answer: a
11. Assertion: A hub is less effective and less intelligent than a Switch
Reason: A Router is least smart and least complicated device.
Answer: c
12. Assertion: A router can work like a bridge and can also handle different protocols.
Reason: A router can locate the destination required by sending the traffic to another router, if the
destination is unknown to itself.
Answer: a
13. Assertion: MAC address is physical address assigned to hardware like Network Interface Cards
Reason: MAC address is assigned by the manufacturer as a unique identifier of the device in a
network.
Answer: a
15. Assertion: Radio wave signals are not effective in few cases.
Reason: Radio wave propagation is susceptible to weather effects like rain, thunderstorms etc.
Answer: a
5. Read the following statements carefully and match whether it is about Client side scripting or
Server side scripting
(i) It is browser dependent
(ii) Script code is downloaded and executed at the client end
(iii) Affected by the processing speed of the host server
(iv) Services are secure as they do not have access to files and databases
(v) The script is executed at server side and the result is sent to client end
Answers:
(i) Client side scripting
(ii) Client side scripting
(iii) Server side scripting
(iv) Client side scripting
(v) Server side scripting
B. Fill in the blanks to complete the sentence from the given set of words.
(Script, cookies, cracker, TCP, IP, HTTPS, IMAP,POP3, telnet, SMTP)
PROTOCOL
1. __________ is a protocol that allows send/upload email message from local computer to an
email server.
2. __________ is like HTTP but a more secure protocol.
3. __________holds email message until user deletes it.
4. __________holds email message on the server until user downloads it.
5. In TCP/IP, the __________protocol is responsible for addressing.
6. In TCP/IP, the __________protocol is responsible for dividing message into multiple packets.
7. __________ protocol facilitates remote logic.
8. A __________ is a malicious hacker.
9. __________ are small text files saved by the website visited.
10. A__________ is a list of commands embedded in a webpage.
pg. 44
C. State whether the following statement are True or False
1. Firewall is a device/software that controls incoming and outgoing network traffic.
2. The HTTP and HTTPS are same protocols.
3. A cracker and a hacker technically do the same work.
4. 3G is an analogue netwotk.
5. POP3 is a protocol for sending files over internet
6. A LAN is a biggest network geographically.
7. A computer is identified by 64 bit IP address.
8. Every object on internet has a unique URL
9. MAC address is 48 bit address
10. LAN is the smallest network geographically.
Answer: 1. T 2. F 3. T 4. F 5. F 6. F 7. F 8. T 9. T 10. T
Q.5 What is the primary advantage of fiber optic cables over copper cables?
a) Lower cost
b) Higher bandwidth and speed
c) Easier installation
d) Greater flexibility
pg. 46
c) Coaxial cable
d) Microwave
Answer: d) Microwave
Q.7 Which type of network uses Bluetooth technology?
a) LAN
b) MAN
c) WAN
d) PAN
Answer: d) PAN
Q.8 What is the maximum length of a Cat 5e Ethernet cable segment?
a) 10 meters
b) 50 meters
c) 100 meters
d) 200 meters
Answer: c) 100 meters
Q.9 Which network device regenerates and amplifies signals?
a) Router
b) Switch
c) Repeater
d) Hub
Answer: c) Repeater
Q. 10 Which type of cable is used to connect different types of devices, like a computer to a
switch?
a) Straight-through cable
b) Crossover cable
c) Coaxial cable
d) Fiber optic cable
Answer: a) Straight-through cable
Q. 11 What does the acronym WAP stand for in networking?
a) Wide Area Protocol
b) Wireless Access Point
c) Wired Access Point
d) Web Application Protocol
Answer: b) Wireless Access Point
Q.12 Which type of switching is used in the Internet?
a) Circuit switching
b) Packet switching
c) Message switching
d) Line switching
Answer: b) Packet switching
Q.15 What type of cable is most commonly used for cable television?
a) Twisted pair cable
b) Coaxial cable
c) Fiber optic cable
d) Ethernet cable
Answer: b) Coaxial cable
Q.17 Which device is used to connect multiple networks and direct data packets between
them?
a) Hub
b) Switch
c) Router
d) Repeater
Answer: c) Router
Q.18 What does Wi-Fi stand for?
a) Wireless Fidelity
b) Wired Fidelity
c) Wireless Fiber
d) Wide Fidelity
Answer: a) Wireless Fidelity
Q.15.The new web standard that incorporates AI, ML and block chain to the internet
is__________
(a) Web 1.0 (b) Web 2.0 (c) Web 3.0 (d) Web 4.0
pg. 49
Q.16.Which of the following are automatically loaded and operates as a part of browser?
a) Add-ons
b) Plug-ins
c) Utilities
d) Widgets
Q.20.Which of the following is used to read a HTML page and render it?
a) Web browser
b) Web server
c) Web matrix
d) Web network
ASSERTION & REASONING
ASSERTION & REASON TYPE QUESTIONS Directions: In the following questions, A statement
of Assertion (A) is followed by a statement of Reason(R).
5. Assertion (A): A router is more powerful and intelligent than hub or switch.
Reason (R): It has advanced capabilities as it can analyses the data and decide the data is
packed and send it to the other network.
6. Assertion (A): The repeater is a device that amplifies the network over geographical
distance.
Reason (R): A hub is a device which is used to connect more than one device in the network.
8. Assertion (A): A protocol means the rules that are applicable for a network.
Reason (R): Local Area Network is an example of protocol.
9. Assertion (A): Short Message Service (SMS) is the transmission of short text messages to
and from a mobile phone, fax machine and/or IP address.
Reason (R): Messages must be no longer than some fixed number of alpha-numeric characters
and contain no images or graphics.
12. Assertion (A): The web is the common name for the World Wide Web, a subset of the
Internet consisting of the pages that can be accessed by a web browser.
Reason (R): URL is a unique identifier used to locate a resource on the Internet.
13. Assertion (A): Static Webpage contains content that do not change or not capable of
typing in new data.
Reason (R): They may only change if the actual HTML file is manually edited.
14. Assertion (A): File Transfer Protocol is a standard for the exchange of files across
internet.
Reason (R): Files of any type can be transferred, whether the file is an ASCII or binary file.
15. Assertion (A): GSM refers to Global System for Mobile communications. It is a technique
that uses narrowband TDMA (Time Division Multiple Access), which allows eight
simultaneous calls on the same radio frequency.
Reason (R): TDMA technology uses time-division multiplexing (TDM) and divides a radio
frequency into time slots and then allocates these slots to multiple calls thereby supporting
multiple, simultaneous data channels.
Answer
1. (b) Circuit switching
2. (a) Packet switched
3. (b) Circuit switched
4. (a) Internet protocol version 4
5. (c) 2 versions
6. (d) 128.64.0.0
7. (c) 128 bits
8. (d) Baud rate
9. (b) Packet switching
10.(c) Circuit switching
MCQ
1 Two-way transmission in which ALL connected devices are transmitting AND receiving
information SIMULTANEOUSLY.
(a)Simplex (b)Full Duplex
(C) LAN Architecture (d)Multiple Devices
Ans:- (b)Full Duplex
2 It is usually privately owned network infrastructure which covers and connects different
devices in a single office, building or campus.
(a)Local Area Network (b)Internet
(c) Personal Area Network (d)Wide Area Network
Ans:- (a)Local Area Network
3 One-way transmission in which each device is either transmit OR receive ONLY.
(a)Half Duplex (b)Firewall
(c) Simplex (d) Ethernet
Ans:- (c) Simplex
4 A network device which extends the range of a signal by receiving then regenerating it and
sending out all other ports.
(a)Repeater (b)Hub
(c)Switch (d)Router
pg. 53
Ans:- (a)Repeater
5 A network security tool used to filter and block unauthorize traffic based on the policies
implemented by the organization.
(a)Router (b)Hub
(c)Firewall (d)Proxy Server
Ans:- (c)Firewall
6 Defines the capability of the network to adapt to change and flexibility to have expansion in
the long run.
(a)Security (b)Scalability
(c)Reliability (d)Availability
Ans:- (b)Scalability
7 Measured by the frequency of failure or the time it takes a link to recover from an outage.
(a)Security (b)Scalability
(c)Reliability (d)Availability
Ans:- (c)Reliability
8 Type of topology which end devices are connected centrally on a hub, also known as "hub-
and-spoke" topology.
(a)Star Topology (b)Mesh Topology
(c)Ring Topology (d)Bus Topology
Ans:- (a)Star Topology
9 A glass or plastic strand that transmits information using light and is made up of one or more
optical fibers.
(a)Twisted Pair Cabling (b)Ethernet
(c)Coaxial Cable (d)Fiber-Optic Cables
Ans:- (d)Fiber-Optic Cables
10 Type of topology where one long cable acts as a backbone to link all the devices in a
network.
(a)Star Topology (b)Mesh Topology
(c)Ring Topology (d)Bus Topology
Ans:- (d)Bus Topology
11 A ________ is a set of rules that governs data communication.
(a)Forum (b)Protocol
(c)Standard (d)None of these
Ans:- (b)Protocol
12 Network in which every computer is capable of playing the role of a client or a server or both
at same time is called
(a)peer-to-peer network (b)local area network
(c)dedicated server network (d)wide area network
Ans:- (a)peer-to-peer network
13 Transmission media are usually categorized as __________
(a) fixed or unfixed (b)determinate or indeterminate.
(c)guided or unguided (d) metallic or nonmetallic.
Ans:- (c)guided or unguided
14 Which of the following primarily uses guided media?
(a)Cellular telephone system (b)Local telephone system
(c)Satellite Communications (d)Radio broadcasting
Ans:- (b)Local telephone system
15 The internetworking protocol is known as
(a)SMTP (b)PPP
(c)TCP/IP (d)NNTP
pg. 54
Ans:- (c)TCP/IP
16 Internet is an example of ____________ topology
(a)Star topology (b)Bus topology
(c)Mesh topology (d)Tree topology
Ans:- (c)Mesh topology
17 _____ Address is assigned to network cards by the manufacturer.
(a)IP (b)MAC (c)Unique (d)domain
Ans:- (b)MAC
18 FTP stands for
(a)File transfer Policy (b)File transfer Protocol
(c)File transmission Protocol (d)File transmission policy
Ans:- (b)File transfer Protocol
19 Which of the following is not a guided communication medium?
(a)Twisted pair cable (b)Microwave
(c)Coaxial cable (d)Optical fibre
Ans:- (b)Microwave
20 What is the size of MAC address?
(a)16 bits (b)32 bits (c)48 bits (d)64 bits
Ans:- (c)48 bits
1. Galaxy Provider Ltd. is planning to connect its office in Texas, USA with its branch at Mumbai.
The Mumbai branch has 3 Offices in three blocks located at some distance from each other
for different operations –ADMIN, SALES and ACCOUNTS.
As a network consultant, you have to suggest the best network related solutions for the
issues/problems raised in (a) to (d), keeping in mind the distances between various locations
and other given parameters.
Q i It is observed that there is a huge data loss during the process of data transfer from one
block to another. Suggest the most appropriate networking device out of the following, which
needs to be placed along the path of the wire connecting one block office with another to
refresh the signal and forward it ahead.
(i) MODEM (ii)ETHERNETCARD
(iii) REPEATER (iv) HUB
Ans:- iii
Qii. Which hardware networking device out of the following, will you suggest to connect all
the computers within each block ?
(i) SWITCH (ii) MODEM
(iii) REPEATER (iv) ROUTER
Ans:- (i)
Qiii. Which service/protocol out of the following will be most helpful to conduct live
interactions of employees from Mumbai Branch and their counterparts in Texas?
(i) FTP (ii) PPP
(iii) SMTP (iv)VoIP
Ans (iv)
Qiv. Draw the cable layout (blocktoblock) to efficiently connect the three offices of the
Mumbai branch.
Ans:
2. Aryan Infotech Solutions has set up its new center at Kamla Nagar for its office and web
based activities. The company compound has 4 buildings as shown in the diagram below:
pg. 56
Orbit Building to Oracle Building 85 Mtrs
Oracle Building to Sunrise Building 25 Mtrs.
3. Magnolia Infotech wants to set up their computer network in the Bangalore based campus
having four buildings. Each block has a number of computers that are required to be
connected for ease of communication, resource sharing and data security. You are required
to suggest the best answers to the questions i) to v) keeping in mind the building layout on
the campus.
pg. 57
Distance Between the various blocks
Block Distance
Development to HR 50m
Development to Admin 75m
Development to Logistics 120m
HR to Admin 110m
HR to Logistics 50m
Admin to Logistics 140m
i) Suggest the most appropriate block to host the Server. Also justify
your choice.
ii) Suggest the device that should be placed in the Server building so that they can connect to
Internet Service Provider to avail Internet Services.
iii) Suggest the wired medium and draw the cable block to block layout to economically
connect the various blocks.
iv) Suggest the placement of Switches and Repeaters in the network
with justification.
v) Suggest the high-speed wired communication medium between
Bangalore Campus and Mysore campus to establish a data network
Ans:-
i) Admin Block since it has maximum number of computers.
ii) Modem should be placed in the Server building
iii) The wired medium is UTP/STP cables.
iv) Switches in all the blocks since the computers need to be connected to the network.
Repeaters between Admin and HR block & Admin and Logistics block. The reason being the
distance is more than 100m.
v) Optical Fiber cable connection
pg. 58
4. 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 Distance between various blocks/locations:
(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.
(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) Suggest a protocol that shall be needed to provide Video Conferencing solution between
Kashipur Campus and Mussoorie Campus.
Ans:-
i) Movie editing block is the most appropriate to house the server as it has the maximum
number of computers.
Ii) Firewall
iii) (iii) Ethernet Cable
(iv)Repeater is not required between the blocks as the distances are less than 100 mts.
(v) Protocol: VoIP
5. An International Bank has to set up its new data center in Delhi, India. It has 5 five blocks
of buildings - A, B, C, D and E.
pg. 59
Distance between the blocks and number of computers in each block areas given below:-
Distance Between Blocks No of Computers
Block B to Block C 30m Block A 55
Block C to Block D 30m Block B 180
Block D to Block E 35m Block C 60
40m 55
Block E to Block C Block D
120m 70
Block D to Block A Block E
45m
Block D to Block B
65m
Block E to Block B
(i) Suggest the most sultadle block to host the server. Justify your answer
(ii) Draw the cable layou slock to Block) to economically connect various blocks within the
Delhi campus of International Bank.
(iii) Suggest the placement ot the following devices with justification:
(a) Repeater
(b) Hub/Switch
(iv)The bank is planning to connect its head office in London. Which type of network out of
LAN, MAN, or WAN will be formed? Justify your answer.
(v) Suggest a device/software to be installed in the Delhi Campus to take care of data security.
pg. 60
6. Ravya Industries has set up its new center at Kaka Nagar for its office and web based
activities. The company compound has 4 buildings as shown in the diagram below:
(iii) Suggest the placement of the following devices with appropriate reasons:
a) Hub/Switch
b)Repeater
(iv) The organisation is planning to link ints sale counter situated in various parts of the same
city, which type of network out of LAN, MAN or WAN will be formed?
(v) Suggest a device/software to be installed in the Campus to take care of data security.
Ans:-
(i) Any one of the following
(ii) The most suitable place / block to house the server of this organisation would be Raj
Building, as this block contains the maximum number of computers, thus decreasing the
cabling cost for most of the computers as well as increasing the efficiency of the maximum
computers in the network.
(iii)
(a) Switch/hub will be placed in all blocks to have connectivity within the block.
(b) Repeater is not required between the blocks as the distances are less than 100 mts.
(iv) MAN, because MAN (Metropolitan Area Networks) are the networks that link computer
facilities within a city.
(v) Firewall
a) Which will be the most appropriate block, where TTC should plan to install their server?
b) Draw a block to block cable layout to connect all the buildings in the most appropriate
manner for efficient communication.
c) What will be the best possible connectivity out of the following, you will suggest to
connect the new setup of offices in Bengalore with its London based office.
● Satellite Link
● Infrared
● Ethernet
d) Which of the following device will be suggested by you to connect each computer in each
of the buildings?
● Switch
● Modem
● Gateway
e) Company is planning to connect its offices in Hyderabad which is less than 1 km. Which
type of network will be formed?
Ans:-
(i) TTC should install its server in finance block as it is having maximum number of computers.
(ii) The layout is based on minimum cable length required, which is 120 metres in the above
case.
pg. 62
Computer sin each block are net worked but blocks are not networked. The company has
now decided to connect the blocks also.
(i) Suggest the most appropriate topology for the connections between the blocks.
(ii) The company wants internet accessibility in all the blocks. The suitable and cost-effective
technology for that would be?
(iii)Which devices will you suggest for connecting all the computers with in each of their
blocks.
(iv)The company is planning to link its head office situated in New Delhi with the offices in
hilly areas. Suggest a way to connect it economically.
(v) Suggest the most appropriate location of the server, to get the best connectivity for
maximum number of computers.
Ans:-
(i)star
(ii)Broadband
(iii)Switch/Hub
(iv)RadioWave
(v)Block B1
pg. 64
10. Perfect Edu Services Ltd. is an educational organization. It is planning to setup its India
campus at Chennai with its head office at Delhi. The Chennai campus has 4 main buildings –
ADMIN, ENGINEERING, BUSINESS and MEDIA. 5
You as a network expert have to suggest the best network related solutions for their
problems raised in (i) to (v), keeping in mind the distances between the buildings and other
given parameters.
(i) Suggest the most appropriate location of the server inside the CHENNAI campus (out of
the 4 buildings), to get the best connectivity for maximum no. of computers. Justify your
answer.
(ii) Suggest and draw the cable layout to efficiently connect various buildings within the
CHENNAI 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) Which of the following will you suggest to establish the online face-to-face
communication between the people in the Admin Office of CHENNAI campus and DELHI
Head Office ?
(a) Cable TV
(b) Email
(c) Video Conferencing
(d) Text Chat
(v) Name protocols used to send and receive emails between CHENNAI and DELHI office?
Ans:-
pg. 65
(i)admin; it contains the max number of systems. to reduce traffic
(ii)
(iii)firewall
(iv) (c) Video Conferencing
(v) POP and SMTP
11. Quick Learn University is setting up its academic blocks at Prayag Nagar and Planning to
set up network. The university has 3 academic blocks and one human resource Centre as
shown in the
diagram given below:
pg. 66
(b) HR centre because it consists of the maximum number of computers to house the
server.
(c) Switch/ Hub should be placed in each of these blocks.
(d) MAN
(e) Bus
12. Rehaana Medicos Center has set up its new center in Dubai. It has four buildings as
shown in the diagram given below:
As a network expert, provide the best possible answer for the following queries:
i) Suggest a cable layout of connections between the buildings.
ii) Suggest the most suitable place (i.e. buildings) to house the server of this organization.
iii) Suggest the placement of the Repeater device with justification.
iv) Suggest a system (hardware/software) to prevent unauthorized access to or from the
network.
(v) Suggest the placement of the Hub/ Switch with justification.
Ans:-
(i) 1 Mark for correct Layout.
(ii) Research Lab ( 1 Mark)
(iii) 1 Mark for correct Justification.
(iv) Antivirus/ Firewall (1 Mark for Correct Answer)
(v) 1 Mark for correct Justification
pg. 67
13. “VidyaDaan” an NGO is planning to setup its new campus at Nagpur for its web-based
activities. The campus has four(04) UNITS as shown below:
ii. Admin
iii. SWITCH/HUB
iv. ADMIN & FINANCE
v. (c) Optical Fiber
pg. 68
14. India Tech Solutions (ITS) is a professional consultancy company. The company is
planning to set up their new offices in India with its hub at Hyderabad. As a network adviser,
you have to understand their requirement and suggest them the best available solutions.
Their queries are mentioned as (i) to (v) below.
Physical locations of the blocks of TTC:-
(i)Which will be the most appropriate block, where TTC 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.
(iii)What will be the best possible connectivity out of the following, you will suggest to
connect the new set up of offices in Bengalore with its London based office.
• Satellite Link
• lInfrared
• Ethernet
(iv) Which of the following device will be suggested by you to connect each computer in
each of the buildings?
• Switch
• Modem
• Gateway
(v) Company is planning to connect its offices in Hyderabad which is less than 1 km. Which
type of network will be formed?
Ans:
(i) TTC should install its server in finance block as it is having maximum number of
computers.
(ii) Any suitable lyout
(iii) Satellite Link.
(iv) Switch.
(v) LAN
15. Total-IT Corporation, a Karnataka based IT training company, is planning to set up training
centers in various cities in next 2 years. Their first campus is coming up in Kodagu district. At
pg. 69
Kodagu campus, they are planning to have 3 different blocks, one for AI, IoT and DS (Data
Sciences) each. 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.
(i) Suggest the most appropriate block/location to house the SERVER in the Kodagu 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 Kodagu Campus to take care of data
security.
(iii) Suggest the best wired medium and draw the cable layout (Block to Block) to most
efficiently connect various blocks within the Kodagu Campus.
(iv) Suggest the placement of the following devices with appropriate reasons:
a) Switch/Hub b) Router
(v) Suggest a protocol that shall be needed to provide Video Conferencing solution between
Kodagu Campus and Coimbatore Campus.
Ans:-
i) IoT block, as it has the maximum number of computers
ii) Firewall
iii) Optical fiber
pg. 73
Assertion & Reasoning
1. Assertion (A) : The 'GROUP BY' clause in SQL is used to aggregate data based on specified
columns.
Reasoning (R ) : The 'GROUP BY' clause is used to group rows that have the same values in
specified columns, often used in conjunction with aggregate functions like SUM, COUNT,
AVG, etc., to perform operations on grouped data.
Answer R is the correct explanation of A
3. Assertion( A) : Natural join can lead to ambiguous column names in the result.
Reason ( R) : Natural join automatically joins tables using columns with the same names.
Answer A is True but R is False
pg. 74
Topic: Python Mysql Connectivity
Q.1.In order to open a connection with MySQL database from within Python using
mysql.connector package, ............... function is used.
1. open()
2. database()
3. connect()
4. connectdb()
Answer
connect()
Reason — The connect() function of mysql.connector is used for establishing connection to
a MYSQL database.
Q.2.A database ............... controls the connection to an actual database, established from
within a Python program.
1. database object
2. connection object
3. fetch object
4. query object
Answer
connection object
Reason — A database connection object controls the connection to the database. It
represents a unique session with a database connected from within a script/program.
Q.3The set of records retrieved after executing an SQL query over an established database
connection is called ............... .
1. table
2. sqlresult
3. result
4. resultset
Answer
resultset
Reason — The result set refers to a logical set of records that are fetched from the database
by executing an SQL query and made available to the application program.
Q.4 A database ............... is a special control structure that facilitates the row by row
processing of records in the resultset.
1. fetch
2. table
3. cursor
4. query
Answer
cursor
Reason — A database cursor is a special control structure that facilitates the row by row
processing of records in the resultset, i.e., the set of records retrieved as per query.
Q.5Which of the following is not a legal method for fetching records from database from
within Python?
1. fetchone()
2. fetchtwo()
pg. 75
3. fetchall()
4. fetchmany()
Answer
fetchtwo()
Reason — The fetchall() method, fetchmany() method, or fetchone() method are the legal
methods used for fetching records from the result set.
Q.6 To obtain all the records retrieved, you may use <cursor>. ............... method.
1. fetch()
2. fetchmany()
3. fetchall()
4. fetchmultiple()
Answer
fetchall()
Reason — The <cursor>.fetchall() method will return all the rows from the resultset in the
form of a tuple containing the records.
Q.7 To fetch one record from the resultset, you may use <cursor>. ............... method.
1. fetch()
2. fetchone()
3. fetchtuple()
4. none of these
Answer
fetchone()
Reason — The <cursor>.fetchone() method will return only one row from the resultset in
the form of a tuple containing a record.
Q.8 To fetch multiple records from the resultset, you may use <cursor>. ............... method.
1. fetch()
2. fetchmany()
3. fetchmultiple()
4. fetchmore()
Answer
fetchmany()
Reason — The <cursor>.fetchmany(<n>) method will return only the <n> number of rows
from the resultset in the form of a tuple containing the records.
Q.9 To run an SQL query from within Python, you may use <cursor>. ............... method().
1. query()
2. execute()
3. run()
4. all of these
Answer
execute()
Reason — The <cursor>.execute() method is used to run an SQL query from within Python.
Q.10 To reflect the changes made in the database permanently, you need to run
<connection>. ............... method.
1. done()
2. reflect()
3. commit()
4. final()
Answer
commit()
pg. 76
Reason — The <connection>.commit() method is used to permanently reflect the changes
made in the database when working with database connections in Python.
1. To open a connector to Mysql database, which statement is used to connect with mysql?
(a) Connector
(b) Connect
(c) password
(d) username
2. Which connector is used for linking the database with Python code?
(a) MySQL-connector
(b) YesSQL: connector
(c) PostSQL: connector
(d) None of the above
3. Which method of cursor class is used to fetch limited rows from the table?
(A) cursor.fetchsize(SIZE)
(B) cursor.fetchmany(SIZE)
(c) cursor.fetchall(SIZE)
(D) cursor.fetchonly(SIZE)
4. Which method of cursor class is used to insert or update multiple rows using a single
Query?
(A) cursor.executeall(query,rows)
(B) cursor.execute(query,rows)
(C) cursor.executemultiple(query,rows)
(D) cursor.executemany(query,rows)
5. Which method of cursor class is used to get the number of rows affected after any of the
Insert/update/delete database operation executed from Python?
(A) cursor.rowcount
(B) cursor.getaffectedcount
pg. 77
(C) cursor.rowscount
(D) cursor.rcount
6. Which of the following is not a legal method for fetching records from database?
a) fetchone()
b) fetchtwo()
c) fetchall()
d) fetchmany()
7. To reflect the changes made in the database permanently you need to run……..
a) done()
b) reflect()
c) commit()
d) final
8. A database …………..controls the connection to an actual database , established in program.
a) database object
b) connection object
c) fetch object
d) query object
9. which method is used to retrieve N number of records
A. fetchone()
B. fetchall()
C. fetchmany()
D. fetchN()
10. In python, execute() method can execute only ________ .
A. Only DQL & DML statements
B. Only DML statements
C. Only DQL statements.
D. DDL, DML & DQL statements.
Q.1 To establish a connection between Python and SQL database, connect() method is
used. Identify the correct syntax of connect( ) method from the followings.
(A) Connect(user=”user name”, passwd=”password”, host=”host name”, database=
“database name”)
pg. 78
(B) Connect(host=”host name”, user=”user name”, password=”password”, database=
“database name”)
(C) Connect(host=”host name”, user=”user name”, passwd=”password”, database=
“database name”)
(D) Connect(host=”host name”, database= “database name”, user=”user name”,
password=”password”)
Case Study 5: Consider the Following tables and write sql query .
Table Customers
CustomerID CustomerName ContactName Country
1 Alfreds Maria Germany
2 Ana Anil Mexico
3 Antonio Antonio Moreno Mexico
4 Rajsons Thomas UK
5 Benzeer Christina Sweden
Table : Orders
OrderID CustomerID OrderDate
10308 2 2024-03-01
10309 37 2024-03-03
10310 77 2024-03-04
10311 3 2024-03-05
10312 5 2024-03-06
a) Write an SQL query to find the orders along with the customer names for only those
orders that have matching customer records.
b) Write an SQL query to find all customers and their orders, including customers who do
not have any orders.
c) Write an SQL query to find all orders and their customer details, including orders that do
not have a matching customer.
d) Write an SQL query to find all customers and all orders, matching them when possible.
pg. 81
Answer a) SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders ,Customers WHERE Orders.CustomerID = Customers.CustomerID;
b) SELECT Customers.CustomerName, Orders.OrderID, Orders.OrderDate
FROM Customers LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID;
c) SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders RIGHT JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
d) SELECT Customers.CustomerName, Orders.OrderID, Orders.OrderDate
FROM Customers FULL OUTER JOIN Orders ON Customers.CustomerID =
Orders.CustomerID;
Case Study 6:- Let's say we have a database for a small online bookstore having following
tables
books: ( book_id, title, author_id, genre_id, price).
authors: (author_id, author_name, birth_year)
genres: (genre_id , genre_name).
customers: (customer_id, customer_name, email)
orders: (order_id, customer_id, order_date, total_amount)
order_details: (order_id, book_id, quantity, unit_price).
a) List all books along with their corresponding authors.
b) Display the total number of orders placed by each customer.
c) List all authors who have written books in the 'Science Fiction' genre.
d) Find the total revenue generated from each genre
Answer
a) SELECT books.title, authors.author_name, genres.genre_name
FROM books ,authors WHERE books.author_id = authors.author_id ;
b) SELECT customers.customer_name, COUNT(orders.order_id) AS total_orders
FROM customers
LEFT JOIN orders ON customers.customer_id = orders.customer_id
GROUP BY customers.customer_name;
c) SELECT DISTINCT authors.author_name
FROM authors
JOIN books ON authors.author_id = books.author_id
JOIN genres ON books.genre_id = genres.genre_id
WHERE genres.genre_name = 'Science Fiction';
d) SELECT genres.genre_name, SUM(order_details.quantity * order_details.unit_price) AS
total_revenue FROM genres
JOIN books ON genres.genre_id = books.genre_id
JOIN order_details ON books.book_id = order_details.book_id
GROUP BY genres.genre_name;
Case Study 7: Bank Database
Consider a bank named "SafeBank" that manages accounts, customers, and transactions.
The bank maintains data about accounts, customers, transactions, and branches in its
database.
Here are the tables in the SecureBank database:
1. accounts: Contains information about bank accounts, including account_number,
customer_id, balance, and branch_id.
pg. 82
2. customers: Stores details about bank customers, such as customer_id, customer_name,
email, and phone_number.
3. transactions: Contains information about transactions, including transaction_id,
account_number, transaction_type, amount, and transaction_date.
4. branches: Stores details about bank branches, including branch_id, branch_name, location,
and manager.
a) List all accounts along with the names of their account holders and their current balances.
b) Find the total balance of all accounts in each branch.
c) Display the names of branches along with the names of their managers.
d) Find the average balance of accounts for each customer.
Answer
a) SELECT a.account_number, c.customer_name, a.balance
FROM accounts a , customers c WHERE a.customer_id = c.customer_id;
pg. 83
Case Study 9 Let's consider two tables, "doctors" and "patients", and generate SQL join
queries based on them.
Table Structures:
doctors: Contains information about doctors. Columns( doctor_id, doctor_name,
specialization, hospital_id)
patients: Stores details about patients. Columns: (patient_id, patient_name, doctor_id,
admission_date)
a) List all patients along with the names of their treating doctors.
b) Show the names of patients who are treated by doctors specializing in 'Cardiology'.
c) List all doctors along with the number of patients they are treating.
d) Find the total number of patients treated in each hospital.
e) Display the names of patients along with their admission dates and the names of their
treating doctors.
Answer
a) SELECT p.patient_id, p.patient_name, d.doctor_name
FROM patients p, doctors d WHERE p.doctor_id = d.doctor_id;
b) SELECT p.patient_name
FROM patients p, doctors d WHERE p.doctor_id = d.doctor_id and d.specialization =
'Cardiology';
c) SELECT d.doctor_name, COUNT(p.patient_id) AS num_patients
FROM doctors d LEFT JOIN patients p ON d.doctor_id = p.doctor_id
GROUP BY d.doctor_name;
d) SELECT d.hospital_id, COUNT(p.patient_id) AS num_patients
FROM doctors d ,patients p WHERE d.doctor_id = p.doctor_id
GROUP BY d.hospital_id;
e) SELECT p.patient_name, p.admission_date, d.doctor_name
FROM patients p, doctors d WHERE p.doctor_id = d.doctor_id;
Case Study 10 :- let's consider two tables, "railway" and "passenger", and generate SQL join
queries based on them.
Table Structures:
railway: Contains information about railway trips. Columns: (trip_id, source_station,
destination_station, departure_time, arrival_time)
passenger: Stores details about passengers on railway trips.Columns( passenger_id, trip_id,
passenger_name, ticket_number, seat_number)
1) List all passengers along with the details of their corresponding railway trips.
2) Display the source and destination stations for all railway trips along with the names of
passengers on each trip.
3) Show the names of passengers who traveled between 'Station A' and 'Station B'.
4) List all railway trips along with the total number of passengers on each trip.
5) Find the total number of passengers who traveled from each source station.
Answer
1) SELECT p.passenger_id, p.passenger_name, r.source_station, r.destination_station,
r.departure_time, r.arrival_time FROM passenger p, railway r WHERE p.trip_id = r.trip_id;
2) SELECT r.trip_id, r.source_station, r.destination_station, p.passenger_name
FROM railway r , passenger p WHERE r.trip_id = p.trip_id;
3) SELECT p.passenger_name
FROM passenger p, railway r WHERE p.trip_id = r.trip_id
And r.source_station = 'Station A' AND r.destination_station = 'Station B';
4) SELECT r.trip_id, COUNT(p.passenger_id) AS num_passengers
FROM railway r, passenger p WHERE r.trip_id = p.trip_id
pg. 84
GROUP BY r.trip_id;
5) SELECT r.source_station, COUNT(p.passenger_id) AS num_passengers
FROM railway r, passenger p WHERE r.trip_id = p.trip_id
GROUP BY r.source_station;
Q2. Assertion( A) : Full outer join can result in null values in the output.
Reason (R) : Full outer join returns all rows when there is a match in one of the tables.
Q4. Assertion (A): A left join can return more rows than the original left table.
Reason (R): Left join returns all rows from the left table, and the matched rows from the
right table.
Q5. Assertion( A) : Using a right join on tables with no matching keys will result in an empty
result set.
Reason( R) : Right join returns all rows from the right table and the matched rows from the
left table.
Q7 Assertion( A) : Natural join can lead to ambiguous column names in the result.
Reason ( R) : Natural join automatically joins tables using columns with the same names.
Q8 Assertion ( A) : Using aliases in joins can improve the readability of the SQL query.
Reason( R) : Aliases provide a shorthand for table names and can simplify the query syntax.
Q9. Assertion (A): Equijoin returns rows where there is an exact match between the
specified columns of the joined tables.
Reason ( R ): Equijoin uses the equality operator (=) to compare columns from the tables
being joined.
Q10. Assertion ( A) : Equijoin can result in duplicated column names in the output.
pg. 85
Reason (R): Equijoin does not automatically remove duplicate columns and includes all
columns from the joined tables.
Answer
Question Answer
1 (a)
2 (a)
3 (a)
4 (d)
5 (d)
6 (a)
7 (c )
8 (a)
9 (a)
10 (a)
pg. 86