QB For Final Revision - CS - XII - 2020 Part-2
QB For Final Revision - CS - XII - 2020 Part-2
print(f4(5,5))
print(f4(12,5))
print(f4(5,12))
3. What will be the content of file abc.txt after execution of the following code?
def f1():
for i in range(10):
f=open("abc.txt",'w')
f.write(str(i))
f.close()
f1()
4. Draw an approximate labelled sketch of the graph/chart generated by the following code. Also
specify the color of the chart:
(i) from matplotlib import pyplot as plt
year = [2010, 2011, 2012, 2013, 2014, 2015]
inflation = [12, 9, 9, 11, 6, 5]
plt.plot(year, inflation, color='g')
plt.xlabel('Years')
plt.ylabel('Rate of Inflation')
plt.title("Inflation Rate 2010-2015")
plt.show()
Differentiate between:
1. Import random and from random import random
2. import math and from math import sqrt
Writing code:
1. Write a function in Python which takes three numbers as parameters and returns the largest of
these three numbers. The function should not use in-built max() function.
2. Write a function in Python which takes a string as a parameter and returns the reversed string
without using slicing.
3. Write a function in Python which takes a string of comma separated words as parameter and
returns a comma separated string in which the words of given string are sorted. For example, if the
given string is "Maths,English,Physics,Chemistry", then the returned string should be:
"Chemistry,English,Maths,Physics".
4. Write a recursive function in Python to calculate and return nth term of Fibonacci series. First few
terms of Fibonacci series are: 0 1 1 2 3 5 8 13 . . .
5. Write a recursive function in Python to perform binary search on a sorted list.
6. Write a recursive function in Python to display first m multiples of n, where m and n are passed as
arguments to the function.
7. Write a recursive function in Python to find the sum of first n terms of the series:
sin(0)+sin(0.1)+sin(0.2)+. . .
8. Write a recursive function in Python to calculate and return the factorial of a number passed as a
parameter.
9. Recursive code to find the sum of all elements of a list.
10. Recursive function to check if a string is palindrome.
15. Write function definition for TOWER() in PYTHON to read the content of a text file
WRITEUP.TXT, count the presence of word TOWER and display the number of occurrences of
this word. (CBSE-Outside Delhi 2015)
Note :
‐ The word TOWER should be an independent word
‐ Ignore type cases (i.e. lower/upper case)
Example:
If the content of the file WRITEUP.TXT is as follows:
16. Write the function definition for WORD4CHAR() in PYTHON to read the content of a text file
FUN.TXT, and display all those words, which have four characters in it.
(CBSE- Delhi 2016)
Example:
If the content of the file Fun.TXT is as follows:
When I was a small child, I used to play in the
garden with my grand mom. Those days were amazingly
funful and I remember all the moments of that time
17. Write function definition for DISP3CHAR() in PYTHON to read the content of a text file
KIDINME.TXT, and display all those words, which have three characters in it.
(CBSE-Outside Delhi 2016)
Example:
If the content of the file KIDINME.TXT is as follows:
18. Write a function in Python to copy the contents of a text file into another text file. The names of
the files should be input from the user.
20. Write a function in Python to input a multi-line string from the user and write this string into a file
named ‘Story.txt’. Assume that the file has to be created.
21. Write a function to display the last line of a text file. The name of the text file is passed as an
argument to the function.
22. Write a function which takes two file names as parameters. The function should read the first
file (a text file), and stores the index of this file in the second file (a binary file). The index should
tell the line numbers in which each of the words appear in the first file. If a word appears more
than once, the index should contain all the line numbers containing the word.
23. Write a Python function to read and display a text file 'BOOKS.TXT'. At the end display number
of lowercase characters, uppercase characters, and digits present in the text file.
24. Write a Python function to display the size of a text file after removing all the white spaces
(blanks, tabs, and EOL characters).
4. Write a function in PYTHON to search for a BookNo from a binary file “BOOK.DAT”, assuming
the binary file is containing the records of the following type:
{"BookNo":value, "Book_name":value}
Assume that BookNo is an integer.
6. Write a function in PYTHON to search for a laptop from a binary file “LAPTOP.DAT” containing
the records of following type. The user should enter the model number and the function should
display the details of the laptop. (CBSE 2011)
[ModelNo, RAM, HDD, Details]
where ModelNo, RAM, HDD are integers, and Details is a string.
7. Write a function in PYTHON to search for the details (Number and Calls) of those mobile
phones which have more than 1000 calls from a binary file “mobile.dat”. Assuming that this
binary file contains records of the following type:
(Number,calls)
8. Write a function in PYTHON to read the records from binary file GAMES.DAT and display the
details of those games, which are meant for children of AgeRange “8 to 13”. Assume that the
file GAMES.DAT contains records of the following type: (CBSE 2013)
[GameCode, GameName, AgeRange];
9. Write a function in PYTHON to read each record of a binary file ITEMS.DAT, find and display
those items which costs less than 2500. Assume that the file ITEMS.DAT is created with the
help of objects of the following type: (CBSE-Delhi 2015)
{"ID":string, "GIFT":string, "Cost":integer};
10. Write a definition for function BUMPER() in PYTHON to read each object of a binary file
GIFTS.DAT, find and display details of those gifts, which have remarks as “ON DISCOUNT”.
Assume that the file GIFTS.DAT is created with the help of lists of following type:
(ID, Gift, Remarks, Price)
(CBSE- Delhi 2016)
Stacks
1. Write functions stackpush(nameStack) to insert a new name and stackpop(nameStack) to
delete a name from a stack implemented using a list. The list is passed as an argument to
these functions.
2. Each element of a stack ITEM (a list) is a list containing two elements BNo (integer), and
Description (String). Write functions to push an element in the stack and to pop an element
from the stack. The popped element should be returned by the function. If the stack is empty,
the pop function should return None.
3. Each element of a stack TEXTBOOKS (a list) is a dictionary with keys 'ISBN', 'TITLE', and
'PRICE'. The values for 'ISBN', 'TITLE', and 'PRICE' are of type integer, string, and float
respectively. Write functions:
(i) PUSH(TEXTBOOKS) to push an element in the stack. The details of the book to be
pushed are to be input from the user.
(ii) POP(TEXTBOOKS) to pop an element from the stack. The popped element should
be returned by the function. If the stack is empty, the pop function should return
None.
Assuming standard definitions of functions PUSH() and POP(), redraw the stack after
performing the following set of operations:
POP(S)
POP(S)
PUSH(S,8)
PUSH(S,3)
POP(S)
(i) POP() (ii) PUSH('Black') (iii) PUSH('Pink') (iv) POP() (v) PUSH('Green')
Queues
1. Write functions Q_insert(nameQueue) to insert a new name and Q_delete(nameQueue) to
delete a name from a queue implemented using a list. The list is passed as an argument to
these functions.
2. Each element of a queue ITEM (a list) is a list containing two elements BNo (integer), and
Description (String). Write functions to insert an element in the queue and to delete an
element from the queue. The deleted element should be returned by the function. If the queue
is empty, the delete function should return None.
3. Each element of a queue TEXTBOOKS (a list) is a dictionary with keys 'ISBN', 'TITLE', and
'PRICE'. The values for 'ISBN', 'TITLE', and 'PRICE' are of type integer, string, and float
respectively. Write functions:
(i) INSERT(TEXTBOOKS) to insert an element in the queue. The details of the book to
be inserted are to be input from the user.
(ii) DELETE(TEXTBOOKS) to delete an element from the queue. The deleteed element
should be returned by the function. If the queue is empty, the delete function should
return None.
(ii) What is the difference between degree and cardinality of a table? What is the degree and
cardinality of the following table: (CBSE 2013)
ENo Name Salary
101 John Fedrick 45000
103 Raya Mazumdar 50600
(iii) Give a suitable example of a table with sample data and illustrate Primary and Alternate keys in
it.
(iv) Observe the following table carefully and write the names of the most appropriate columns,
which can be considered as (i) candidate keys and (ii) primary key.
(CBSE-Delhi 2015)
Id Product Qty Price Transaction Date
101 Plastic Folder 12" 100 3400 2014-12-14
104 Pen Stand Standard 200 4500 2015-01-31
105 Stapler Medium 250 1200 2015-02-28
109 Punching Machine Big 200 1400 2015-03-12
103 Stapler Mini 100 1500 2015-02-02
(v) Observe the following table carefully and write the names of the most appropriate columns,
which can be considered as (i) candidate keys and (ii) primary key.
(CBSE-Outside Delhi 2015)
(vi) Observe the following STUDENTS and EVENTS tables carefully and write the name of the RDBMS
operation which will be used to produce the output as shown in LIST. Also, find the Degree and
Cardinality of the LIST. (CBSE- Delhi 2016)
STUDENTS EVENTS
No Name EVENTCODE EVENTNAME
1 Tara mani 1001 Programming
2 Jaya Sarkar 1002 IT Quiz
3 Tarini Trikha
LIST
NO NAME EVENTCODE EVENTNAME
1 Tara mani 1001 Programming
1 Tara mani 1002 IT Quiz
2 Jaya Sarkar 1001 Programming
2 Jaya Sarkar 1002 IT Quiz
3 Tarini Trikha 1001 Programming
3 Tarini Trikha 1002 IT Quiz
(vii) Observe the following PARTICIPANTS and EVENTS tables carefully and write the name of the
RDBMS operation which will be used to produce the output as shown in RESULT. Also, find the
Degree and Cardinality of the RESULT. (CBSE- Outside Delhi 2016)
PARTICIPANTS EVENTS
PNo Name EVENTCODE EVENTNAME
1 Aruanabha Tariban 1001 IT Quiz
2 John Fedricks 1002 Group Debate
3 Kanti Desai
RESULT
PNO NAME EVENTCODE EVENTNAME
1 Aruanabha Tariban 1001 IT Quiz
1 Aruanabha Tariban 1002 Group Debate
2 John Fedricks 1001 IT Quiz
2 John Fedricks 1002 Group Debate
3 Kanti Desai 1001 IT Quiz
3 Kanti Desai 1002 Group Debate
(iii) Write SQL commands for the following queries on the basis of Club relation given below:
Coach-ID CoachName Age Sports date_of_app Pay Sex
1 Kukreja 35 Karate 27/03/1996 1000 M
2 Ravina 34 Karate 20/01/1998 1200 F
3 Karan 34 Squash 19/02/1998 2000 M
4 Tarun 33 Basketball 01/01/1998 1500 M
5 Zubin 36 Swimming 12/01/1998 750 M
6 Ketaki 36 Swimming 24/02/1998 800 F
7 Ankita 39 Squash 20/02/1998 2200 F
8 Zareen 37 Karate 22/02/1998 1100 F
9 Kush 41 Swimming 13/01/1998 900 M
10 Shailya 37 Basketball 19/02/1998 1700 M
a) To show all information about the swimming coaches in the club.
b) To list the names of all coaches with their date of appointment (date_of_app) in
descending order.
c) To display a report showing coach name, pay, age, and bonus (15% of pay) for all
coaches.
d) To insert a new row in the Club table with ANY relevant data:
e) Give the output of the following SQL statements:
i. Select COUNT(Distinct Sports) from Club;
ii. Select Min(Age) from Club where SEX = “F”;
(iv) Write SQL commands for (a) to (f) and write the outputs for (g) on the basis of tables
FURNITURE and ARRIVALS
ARRIVALS
NO ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT
1 Wood Comfort Double Bed 23/03/03 25000 25
2 Old Fox Sofa 20/02/03 17000 20
3 Micky Baby cot 21/02/03 7500 15
a) To show all information about the Baby cots from the FURNITURE table.
b) To list the ITEMNAME which are priced at more than 15000 from the FURNITURE table.
c) To list ITEMNAME and TYPE of those items, in which date of stock is before 22/01/02
from the FURNITURE table in descending of ITEMNAME.
d) To display ITEMNAME and DATEOFSTOCK of those items, in which the discount
percentage is more than 25 from FURNITURE table.
e) To count the number of items, whose TYPE is "Sofa" from FURNITURE table.
f) To insert a new row in the ARRIVALS table with the following data:
14,“Valvet touch”, "Double bed", {25/03/03}, 25000,30
g) Give the output of following SQL stateme
Note: Outputs of the above mentioned queries should be based on original data
given in both the tables i.e., without considering the insertion done in (f) part of
this question.
(i) Select COUNT(distinct TYPE) from FURNITURE;
(ii) Select MAX(DISCOUNT) from FURNITURE,ARRIVALS;
(iii) Select AVG(DISCOUNT) from FURNITURE where TYPE="Baby cot";
(iv) Select SUM(Price) from FURNITURE where DATEOFSTOCK<{12/02/02};
(v) Consider the following tables GAMES and PLAYER. Write SQL commands for the statements
(a) to (d) and give outputs for SQL queries (E1) to (E4)
GAMES
GCode GameName Number PrizeMoney ScheduleDate
101 Carom Board 2 5000 23-Jan-2004
102 Badminton 2 12000 12-Dec-2003
103 Table Tennis 4 8000 14-Feb-2004
105 Chess 2 9000 01-Jan-2004
108 Lawn Tennis 4 25000 19-Mar-2004
PLAYER
PCode Name Gcode
1 Nabi Ahmad 101
2 Ravi Sahai 108
3 Jatin 101
4 Nazneen 103
TRADERS
TCode TName CITY
T01 ELECTRONIC SALES MUMBAI
T03 BUSY STORE CORP DELHI
T02 DISP HOUSE INC CHENNAI
a) To display the details of all the items in the ascending order of item names (i.e.
INAME).
b) To display item name and price of all those items, whose price is in range of
10000 and 22000 (both values inclusive).
c) To display the number of items, which are traded by each trader. The expected
output of this query should be:
T01 2
T02 2
T03 1
d) To display the price, item name and quantity (i.e. qty) of those items which
have quantity more than 150.
e) To display the names of those traders, who are either from DELHI or from
MUMBAI.
f) To display the names of the companies and the names of the items in descending
order of company names.
g1 ) SELECT MAX(PRICE), MIN(PRICE) FROM ITEMS;
g2 ) SELECT PRICE*QTY AMOUNT FROM ITEMS WHERE CODE-1004;
g3 ) SELECT DISTINCT TCODE FROM ITEMS;
g4 ) SELECT INAME, TNAME FROM ITEMS I, TRADERS T WHERE I.TCODE=T.TCODE
AND QTY<100;
Table: DEPT
DCODE DEPARTMENT CITY
D01 MEDIA DELHI
D02 MARKETING DELHI
D03 INFRASTRUCTURE MUMBAI
D05 FINANCE KOLKATA
D04 HUMAN RESOURCE MUMBAI
Table: WORKER
WNO NAME DOJ DOB GENDER DCODE
1001 George K 2013-09-02 1991-09-01 MALE D01
1002 Ryma Sen 2012-12-11 1990-12-15 FEMALE D03
1003 Mohitesh 2013-02-03 1987-09-04 MALE D05
1007 Anil Jha 2014-01-17 1984-10-19 MALE D04
1004 Manila Sahai 2012-12-09 1986-11-14 FEMALE D01
1005 R SAHAY 2013-11-18 1987-03-31 MALE D02
1006 Jaya Priya 2014-06-09 1985-06-23 FEMALE D05
Note: DOJ refers to date of joining and DOB refers to date of Birth of workers.
(xi) Consider the following DEPT and EMPLOYEE tables. Write SQL queries for (i) to (iv) and
find outputs for SQL queries (v) to (viii). (CBSE-Outside Delhi 2015)
Table: DEPT
DCODE DEPARTMENT LOCATION
D01 INFRASTRUCTURE DELHI
D02 MARKETING DELHI
D03 MEDIA MUMBAI
D05 FINANCE KOLKATA
D04 HUMAN RESOURCE MUMBAI
Table: EMPLOYEE
ENO NAME DOJ DOB GENDER DCODE
1001 George K 20130902 19910901 MALE D01
1002 Ryma Sen 20121211 19901215 FEMALE D03
1003 Mohitesh 20130203 19870904 MALE D05
1007 Anil Jha 20140117 19841019 MALE D04
1004 Manila Sahai 20121209 19861114 FEMALE D01
1005 R SAHAY 20131118 19870331 MALE D02
1006 Jaya Priya 20140609 19850623 FEMALE D05
Note: DOJ refers to date of joining and DOB refers to date of Birth of employees.
(i) To display Eno, Name, Gender from the table EMPLOYEE in ascending order of Eno.
(ii) To display the Name of all the MALE employees from the table EMPLOYEE.
(iii) To display the Eno and Name of those employees from the table EMPLOYEE who
are born between '1987‐01‐01' and '1991‐12‐01'.
(iv) To count and display FEMALE employees who have joined after '1986‐01‐01'.
(v) SELECT COUNT(*),DCODE FROM EMPLOYEE
GROUP BY DCODE HAVING COUNT(*)>1;
(vi) SELECT DISTINCT DEPARTMENT FROM DEPT;
(vii) SELECT NAME, DEPARTMENT FROM EMPLOYEE E, DEPT
D WHERE E.DCODE=D.DCODE AND EN0<1003;
(viii) SELECT MAX(DOJ), MIN(DOB) FROM EMPLOYEE;
(xii) Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on
the tables. (CBSE- Delhi 2016)
Table: VEHICLE
Code VTYPE PERKM
101 VOLVO BUS 160
102 AC DELUXE BUS 150
103 ORDINARY BUS 90
105 SUV 40
104 CAR 20
Note:
• PERKM is Freight Charges per kilometer
• VTYPE is Vehicle Type
Note :
• NO is Traveller Number
• KM is Kilometer travelled
• NOP is number of travellers travelled in vehicle
• TDATE is Travel Date
(i) To display NO, NAME, TDATE from the table TRAVEL in descending order of NO.
(ii) To display the NAME of all the travellers from the table TRAVEL who are travelling
by vehicle with code 101 or 102.
(iii) To display the NO and NAME of those travellers from the table TRAVEL who
travelled between ‘2015-12-31’ and ‘2015-04-01’.
(iv) To display all the details from table TRAVEL for the travellers, who have travelled
distance more than 100 KM in ascending order of NOP.
(v) SELECT COUNT (*), CODE FROM TRAVEL GROUP BY CODE HAVING
COUNT(*)>1;
(vi) SELECT DISTINCT CODE FROM TRAVEL;
(vii) SELECT A.CODE,NAME,VTYPE FROM TRAVEL A,VEHICLE B WHERE
A.CODE=B.CODE AND KM<90;
(viii) SELECT NAME,KM*PERKM FROM TRAVEL A, VEHICLE B WHERE
A.CODE=B.CODE AND A.CODE=‘105’;
(xiii) Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on
the tables. (CBSE- Outside Delhi 2016)
Table: VEHICLE
VCODE VEHICLETYPE PERKM
V01 VOLVO BUS 150
V02 AC DELUXE BUS 125
V03 ORDINARY BUS 80
V05 SUV 30
V04 CAR 18
Note:
• PERKM is Freight Charges per kilometer
Table: TRAVEL
CNO CNAME TRAVELDATE KM VCODE NOP
101 K.Niwal 2015-12-13 200 V01 32
103 Fredrick Sym 2016-03-21 120 V03 45
105 Hitesh Jain 2016-04-23 450 V02 42
102 Ravi anish 2016-01-13 80 V02 40
107 John Malina 2015-02-10 65 V04 2
104 Sahanubhuti 2016-01-28 90 V05 4
106 Ramesh jaya 2016-04-06 100 V01 25
Note :
• KM is Kilometer travelled
• NOP is number of travellers travelled in vehicle
• TDATE is Travel Date
(i) To display CNO, CNAME, TRAVELDATE from the table TRAVEL in descending
order of CNO.
(ii) Granuda Consultants are setting up a secured network for their office campus at Faridabad for their
day to day office and web based activities. They are planning to have connectivity between 3
buildings and the head office situated in Kolkata. Answer the questions (a) to (d) after going through
the building positions in the campus and other details, which are given below: (CBSE 2012)
(iii) Expertia Professional Global (EPG) is an online corporate training provider company for IT related
courses. The company is setting up their new campus in Mumbai. You as a network expert have
to study the physical locations of various buildings and the number of computers to be installed. In
the planning phase, provide the best possible answers for the queries (a) to (d) raised by them.
(CBSE 2013)
(iv) Trine Tech Corporation (TTC) 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 (a) to (d) below. (CBSE 2014)
a) What will be the most appropriate block, where TTC should plan to install the 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 Bangalore with its London based office?
Satellite Link, Infrared, Ethernet cable
d) Which of the following devices will be suggested by you to connect each computer in each of the
buildings.
Switch, modem, Gateway
(v) 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 (CBSE 2015)
(vi) Xcelencia Edu Services Ltd. is an educational organization. It is planning to set up its India campus
at Hyderabad with its head office at Delhi. The Hyderabad campus has 4 main buildings:
ADMIN, SCIENCE, BUSINESS and MEDIA. (CBSE-Outside Delhi 2015)
You as a network expert have to suggest the best network related solutions for their problems
raised in (a) to (d), keeping in mind the distances between the buildings and other given
parameters.
(vii) Uplifting Skills Hub India is a knowledge and skill community which has an aim to uplift the standard
of knowledge and skills in the society. It is planning to setup its training centers in multiple towns
and villages pan 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 follows:
As a network consultant, you have to suggest the best network related solutions for their
issues/problems raised in (a) to (d) keeping in mind the distances between various locations and
other given parameters.
Note :
• In Villages, there are community centers, in which one room has been given as training
center to this organization to install computers.
• The organization has got financial support from the government and top IT companies.
a) Suggest the most appropriate location of the SERVER in the B_HUB (out of the 4
locations), to get the best and effective connectivity. Justify your answer.
b) Suggest the best wired medium and draw the cable layout (location to location) to
efficiently connect various locations within the B_HUB.
c) Which hardware device will you suggest to connect all the computers within each
location of B_HUB?
d) Which service/protocol will be most helpful to conduct live interactions of Experts
from Head Office and people at all locations of B_HUB?
Note:
• In Villages, there are community centers, in which one room has been given as training center to
this organization to install computers.
• The organization has got financial support from the government and top IT companies.
a) 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.
b) Suggest the best wired medium and draw the cable layout (location to location) to efficiently
connect various locations within the YHUB.
c) Which hardware device will you suggest to connect all the computers within each location of
YHUB?
d) Which service/protocol will be most helpful to conduct live interactions of Experts from Head
Office and people at YHUB locations?
19. Which of the following crime(s) is/are covered under cybercrime? (CBSE 2013)
(i) Stealing brand new hard disk from a shop
(ii) Getting into unknown person’s social networking account and start messaging on his
behalf.
(iii) Copying some important data from a computer without taking permission from the owner
of the data.
ANSWERS
Descriptive Questions:
1. A function is a named group of statements which get executed when the function is invoked.
2.
Actual Parameters Formal Parameter
Parameter used in function call. Parameter used in function definition.
Can be a variable, a literal, or any other valid Has to be a variable only.
expression.
Example:
def func(a,b):
print(a,b)
r=1
func(3,r*2)
In the above code, 3 and r*2 in the function call are actual parameters, whereas a and b in
the function header are formal parameters.
3.
Value Parameter Reference Parameter
It is a copy of the corresponding actual It is an alias of the corresponding reference
parameter. parameter.
Any change in a value parameter does not Any change in a reference parameter is
affect the corresponding actual parameter. reflected on the corresponding actual
parameter too.
All immutable data objects are accepted as All mutable data objects are accepted as
value parameters in a function. reference parameters in a function.
Example:
def func(a,b):
a[b]+=1
b+=1
arr=[1,2,3,4]
n=2
func(arr,n)
print(arr,n)
15.
def func(x): ->Function header, formal parameter - b
global b
y=b+2
b*=y function body
y+=x+b
print(x,y,b)
x,b=5,10
func(x) -> Function Call, Actual parameter - x
print(func(x)) -> Function Call, Actual parameter - x
16. A module is a python script (a .py file) containing one or more of the following components: declarations
(classes, objects, variables etc.), function definitions, function calls, independentt statements
(executable code outside a function).
17. A package is a folder containing one or more modules and a file __init__.py. The presence of the file
__init__.py, even if empty, lets python treat a folder as a package to be imported in other modules, if
required. Without __init__.py, a folder is just a normal folder and cannot be treated as a package.
18. A library is a collection of
19.
(i) From myModule import alpha
(ii) From Computer import comp1(), comp2()
(iii) From lib import pkg
(iv) From HR import Salary
(v) Import Trigonometry
20. A file is a named collection of data stored on a secondary storage device.
21. Files are needed for permanent storage of data.
22. Text file and Binary file.
23.
Text File Binary File
A text file can be created using any text editor or A binary file can be created using only a
a computer program. computer program.
A text file can be opened meaningfully using any A binary file can be read meaningfully only
text editor or a computer program. by a computer program.
(ii)
(iii)
(iv)
Differentiate between:
1. Import random and from random import random
Import random From random import random
Imports the complete random module Imports only the function random() from the
random module
Any function from the random module can be Only the imported function can be used in the
used in the code code.
Function call needs to be qualified by prefixing No prefix is needed with the function call
module name random with the function call.
Example: random.random() Example: random()
Writing code:
1. def high(a,b,c):
if a>=b and a>=c:
return a
if b>=c and b>=a:
return b
if c>=a and c>=b:
return c
2. def rev_str(s):
s1=''
for ch in s:
s1=ch+s1
return s1
3. def sort_words(s):
s=s.split(',')
s.sort()
s=','.join(s)
return s
4. def fibo(n):
if n<=1:
return n
else: return fibo(n-1)+fibo(n-2)
5. def binSearch(A,ele,beg=0,end=None):
if end==None:
end=len(A)
if beg>end:
return None;
else:
mid=(beg+end)//2
if A[mid]==ele:
return mid
elif A[mid]>ele:
return binSearch(A,ele,beg,mid-1)
else: return binSearch(A,ele,mid+1,end)
6. def multiples(m,n,start=1):
if start==m+1:
return
else:
print(n*start)
start+=1
multiples(m,n,start)
7. def sum_sin(n):
from math import sin
if n==1:
return sin(0)
else:
return sin((n-1)*0.1)+sum_sin(n-1)
8. def fact(n):
if n<=1:
return 1
else: return n*fact(n-1)
9. def sumArray(A):
l=len(A)
if l==0:
return 0
else: return A[0]+sumArray(A[1:])
7. def last_three():
f=open("story.txt")
data=f.read()
data=data.strip()
print(data[-3:])
f.close()
Stacks
1. def stackpush(nameStack):
nm=input("Enter name to push: ")
nameStack.insert(0,nm)
def stackpop(stack):
if nameStack==[]:
return None
else:
return nameStack.pop(0)
2. def stackpush(stack):
bn=int(input("Enter BNo: "))
Desc=input("Enter Description: ")
ele=[bn,Desc]
stack.insert(0,ele)
def stackpop(stack):
if stack==[]:
return None
else:
return stack.pop(0)
3. def PUSH(TEXTBOOKS):
isbn=int(input("Enter ISBN: "))
title = input("Enter title: ")
price=float(input("Enter price: "))
ele={'ISBN':isbn,'TITLE':title,'PRICE':price}
TEXTBOOKS.insert(0,ele)
def POP(TEXTBOOKS):
if TEXTBOOKS==[]:
return None
else:
return TEXTBOOKS.pop(0)
4.
5.
def q_delete(queue):
if queue==[]:
return None
else:
return queue.pop(0)
3. def INSERT(TEXTBOOKS):
isbn=int(input("Enter ISBN: "))
title = input("Enter title: ")
price=float(input("Enter price: "))
ele={'ISBN':isbn,'TITLE':title,'PRICE':price}
TEXTBOOKS.append(ele)
def DELETE(TEXTBOOKS):
if TEXTBOOKS==[]:
return None
else:
return TEXTBOOKS.pop(0)
(ii) Degree of a table is the number of coulmns (attributes) in It, whereas Cardinality is the number of
rows (tuples) in it.
Degree of the given table is 3 and its Cardinality is 2.
(iii) A table may have more than one such attribute/group of attributes that identify a row/tuple
uniquely. All such attribute(s)/group(s) are known as Candidate keys. Out of the candidate keys,
one is selected as primary key and the other keys are known an alternate keys.
Example:
Relation: Stock
Ino Item Qty Price
I01 Pen 560 2
I02 Pencil 600 1
I03 CD 200 3
In this relation Ino and Item are Candidate keys. If Ino is selected as the primary key, then Item
will be the alternate key, and vice-versa.
(v)
a) SELECT GAMENAME, GCODE FROM GAMES;
b) SELECT * FROM GAMES WHERE PRZEMONEY > 7000;
c) SELECT * FROM GAMES ORDER BY SCHEDULEDATE;
d) SELECT NUMBER, SUM(PRIZEMONEY) FROM GAMES GROUP BY NUMBER;
(e1) 2
4
(e2) MAX(ScheduleDate) MIN(ScheduleDate)
----------------- -----------------
19-Mar-2004 12-Dec-2003
(e3) 59000
(e4) 101
108
103
(vi)
(a)
(i) SELECT * FROM WORKER ORDER BY DOB DESC;
(ii) SELECT NAME, DESIG FROM WORKER WHERE PLEVEL IN (“P001”, “P002”);
(iii) SELECT * FROM WORKER WHERE DOB BETWEEN “19-JAN-1984” AND “18-JAN-
1987”;
(iv) INSERT INTO WORKER VALUES
(19, ‘Daya kishore’, ‘Operator’, ‘P003’, ’19-Jun-2008’, ’11-Jul-
1984’);
(b)
(i)
COUNT(PLEVEL) PLEVEL
1 P001
2 P002
2 P003
(ii)
MAX(DOB)) MIN(DOJ)
12-Jul-1987 13-Sep-2004
(iii)
Name Pay
Radhey Shyam 26000
Chander Nath 12000
(iv)
PLEVEL PAY+ALLOWANCE
P003 18000
(vii)
(a)
1) SELECT VehicleName FROM CARHUB WHERE Color = ‘WHITE’;
2) SELECT VehicleName, Make, Capacity FROM CARHUB ORDER BY CAPACITY;
3) SELECT MAX(Charges) FROM CARHUB;
4) SELECT CName, VehicleName, FROM CUSTOMER, CARHUB
WHERE CUSTOMER.Vcode = CARHUB.Vcode;
(b)
1)
COUNT(DISTINCT Make)
4
2)
MAX(Charges) MIN(Charges)
35 12
(viii)
a) SELECT * FROM ITEMS ORDER BY INAME;
b) SELECT INAME, PRICE FROM ITEMS WHERE PRICE BETWEEN 10000 AND 22000;
c) SELECT TCODE, COUNT(*) FROM ITEMS GROUP BY TCODE;
d) SELECT PRICE, INAME, QTY FROM ITEMS WHERE QTY > 150;
e) SELECT INAME FROM TRADERS WHERE CITY IN (‘DELHI’, ‘MUMBAI’);
f) SELECT COMPANY, INAME FROM ITEMS ORDER BY COMPANY DESC;
g1)
MAX(PRICE) MIN(PRICE)
38000 1200
g2)
AMOUNT
1075000
g3)
DISTINCT TCODE
T01
T02
T03
g4)
INAME TNAME
LED SCREEN 40 DISP HOUSE INC
CAR GPS SYSTEM ELECTRONIC SALES
(ix)
(a)
1) SELECT IName, price from Item ORDER BY Price;
2) SELECT SNo, SName FROM Store WHERE Area=’CP’;
3) SELECT IName, MIN(Price), MAX(Price) FROM Item GROUP BY IName;
4) SELECT IName, Price, SName FROM Item, Store Where Item.SNo =
Store.SNo;
(b)
1)
DISTINCT INAME
Hard disk
LCD
Mother Board
2)
Area Count(*)
CP 2
GK II 1
Nehru Place 2
3)
COUNT(DISTINCT AREA)
3
4)
INAME DISCOUNT
Keyboard 25
Mother Board 650
Hard Disk 225
(v)
COUNT(*) DCODE
2 D01
2 D05
(vi)
Department
MEDIA
MARKETING
INFRASTRUCTURE
FINANCE
HUMAN RESOURCE
(vii)
NAME DEPARTMENT CITY
George K MEDIA DELHI
Ryma Sen INFRASTRUCTURE MUMBAI
(viii)
MAX(DOJ) MIN(DOB)
2014-06-09 1984-10-19
(xi)
(i) SELECT Eno,Name,Gender FROM Employee ORDER BY Eno;
(ii) SELECT Name FROM Employee WHERE Gender=’MALE’;
(iii) SELECT Eno,Name FROM Employee
WHERE DOB BETWEEN ‘19870101’ AND ‘19911201’;
OR
SELECT Eno,Name FROM Employee
WHERE DOB >=‘19870101’ AND DOB <=‘19911201’;
OR
SELECT Eno,Name FROM Employee
WHERE DOB >‘19870101’ AND DOB <‘19911201’;
(xii)
(i) SELECT NO, NAME, TDATE FROM TRAVEL ORDER BY NO DESC;
(xiii)
(i) SELECT CNO, CNAME, TRAVELDATE FROM TRAVEL ORDER BY CNO DESC;
17. FTP
18. Speed ‐
• Faster web browsing
• Faster file transfer
Service ‐
• Better video clarity
• Better security
19. The Internet of Things (IoT) is a system of interrelated computing devices, mechanical and digital machines,
objects, animals or people that are provided with unique identifiers (UIDs) and the ability to automatically
transfer data over a network without requiring human-to-human or human-to-computer interaction.
20. Client–server model is a computing model where a device/software (called client) requests another
device/software (called server) to provide some services. The requested services are then provided by the
server to the client. In a client-server setup there can be multiple clients and multiple servers.
21. Cloud computing is the delivery of on-demand computing services over the Internet on a pay-as-you-go
basis. Three types of services provided on cloud are:
(i) SaaS: Software as a Service
(ii) IaaS: Infrastructure as a Service
(iii) PaaS: Platform as a Service
22. Advantages:
(i) Pay for what you use.
(ii) Better data security
Disadvantages/Limitations:
(i) Totally dependent on availability and speed of Internet connectivity.
(ii) More money is to be paid if more features are required.
23. Public cloud is a cloud service offered to multiple customers by a cloud provider. For example Microsoft
Azure is a public cloud.
24. A private cloud consists of computing resources used exclusively by one business or organization. The
private cloud can be physically located at the organization’s on-site data center, or it can be hosted by a
third-party service provider. Example – Cloud maintained by NIC (National Informatics Center).
25. Attenuation: Reduction in the strength of a signal during transmission. It happens when a signal travels
long distances over a network.
26. IPv4 is a 32 bit address, whereas IPv6 is a 128 bit address. Examples:
IPv4: 192.168.72.54 IPv6: 2001:0cb8:85a3:0000:0000:8c2e:0370:7a34
27. Carrier waves are the electromagnetic waves (radio waves, micro waves, and infrared waves) which are
used as carriers of the data. Signals waves are the waves which represent the actual data to be carried.
28. Modulation: The process of mounting the data signals on carrier signals is called modulation.
Demodulation: The process of separating the data signals from carrier waves is called demodulation.
29. (i) FM signals give better quality than AM signals
(ii) AM signals can cover longer distances than FM signals.
(iii)The equipment requirements for FM system are costly as compared to that for AM system.
30. Collision in a network means two or more nodes simultaneously try to send the data on a common medium.
Performance of the network goes down due to collisions.
31. Collision prevention refers to ways to avoid collisions in a network. CSMA/CA protocol is used for collision
avoidance. Collision resolution refers to the process of resolving the collision, if there is any.
33. (i) Ping: It is a network tool used to provide a basic connectivity test between the requesting host and a
destination host. This is done by sending an echo packet to a destination host and listening for a response
from this host. Example: ping google.com
(ii) Traceroute (tracert): The tracert/traceroute utility is used to determine specific information about the
path to a destination host including the route the packet takes and the response time of these intermediate
hosts. Example: traceroute google.com
(iii) Ipconfig: This utility is used to find out and control the IP configuration information of a computer.
(iv) Nslookup: This utility is used to lookup the specific IP address(es) associated with a domain name. If
this utility is unable to resolve this information, there is a DNS issue.
Example: nslookup www.google.com returns 172.217.20.68
(v) WHOIS is a query and response protocol that is widely used for querying databases that store the
registered users or assignees of an Internet resource, such as a domain name, an IP address block or an
autonomous system, but is also used for a wider range of other information.
(vi) Speed test: A very easy test that can be used to both determine the Internet bandwidth available to a
specific host and to determine the quality of an Internet connection is the use of the tools available at the
speedtest.net and pingtest.net websites.
34. (a) ping (b) ping (c) traceroute (d) nslookup (e) whois (f) ipconfig (g) ipconfig (h) nslookup (i)
speedtest (j) speedtest
35.
Physical Address Logical Address
It is the MAC address of the NIC of the device. It is the IP address of the device.
It is used by switches for communication within a It is used by routers for communication
network. between networks.
36. Guided media refers to cables such as Twisted Pair cables, Coaxial cables, and Optical Fiber cables.
Unguided media refers to waves such as radio waves, micro waves, and infrared rays.
37. (i) Remote Login: Using remote login, a user is able to access a computer or a network remotely through a
network connection. Remote login enables users to access the systems they need when they are not
physically able to connect directly.
(ii) Remote Desktop: Remote desktop is a program or an operating system feature that allows a user to
connect to a computer in another location, see that computer's desktop and interact with it as if it were
local.
38. Application Layer is the top most Layer of a computer network, and is implemented in end nodes e.g.
computers. Some protocols of Application Layer are FTP(File Transfer Protocol), HTTP (Hyper Text Transfer
Protocol) , SMTP (Simple Mail Transfer Protocol) etc.
39. (i) Wi-fi is a technology that is used for short distance wireless communication. Wi-Fi uses radio waves of
frequency 2.4GHz and 5GHz.
(ii) Access Point: It is a device in a wireless network that broadcasts a wireless signal that devices can detect
and "tune" into.
40. DNS (domain name system): It is a system of remote servers used to convert domain names to their
corresponding IP addresses.
c) Switch
d) WAN as the given distance is more than the range of LAN and MAN.
(ii)
a) Building “Jamuna” as it contains the maximum number of computers.
b)
c)
(i) Switch is needed to be placed in each building to interconnect the computers within
that building.
(ii) Repeater is needed to be placed between “Jamuna” and “Ravi” as the distance is
more than 90m.
(iii)
a) Faculty Studio as it contains the maximum number of computers.
b)
c) LAN
d) Satellite
(iv)
a) Finance
b)
(v)
a) ADMIN (due to maximum number of computers)
OR
MEDIA (due to shorter distance from the other buildings)
c) Firewall OR Router
d) Video Conferencing
(vi)
a) ADMIN (due to maximum number of computers)
OR
ARTS (due to shorter distance from the other buildings)
c) Firewall OR Router
d) Video Conferencing
(vii)
a) B_TOWN. Since it has the maximum number of computers and is closest to all other
locations.
b)
c) Switch OR Hub
d) Videoconferencing OR VoIP OR any other correct service/protocol
(viii)
a) B_TOWN. Since it has the maximum number of computers and is closest to all other
locations
c) Switch OR Hub
d) Videoconferencing OR VoIP OR any other correct service/protocol