Xii CSC Worksheets All Chapters
Xii CSC Worksheets All Chapters
15. Write the Python statement for each of the following tasks using BUILT-IN
functions/methods only:
(i) To insert an element 200 at the third position, in the list L1.
(ii) To check whether a string named, message ends with a full stop / period or not.
16. A list named studentAge stores age of students of a class. Write the Python
command to import the required module and (using built-in function) to display the
most common age value from the given list.
17. Rewrite the following code in Python after removing all syntax error(s) : 2 Underline
each correction done in the code.
Runs = (10, 5, 0, 2, 4, 3)
for I in Runs:
if I=0:
Revision Tour - Worksheet – 1 – 2 Marks Page 4
print(Maiden Over)
else
print(Not Maiden)
18. What possible output(s) is/are expected to be displayed on the screen at the time of
execution of the program from the following code ? Also specify the maximum and
minimum value that can be assigned to the variable R when K is assigned value as 2.
import random
Signal = ['Stop', 'Wait', 'Go' ]
for K in range(2, 0, -1):
R = randrange(K)
print (Signal[R], end = ' # ')
(a) Stop # Wait # Go # (b) Wait # Stop # (c) Go # Wait # (d) Go # Stop #
19. Write the output for the execution of the following Python code :
def change(A):
S=0
for i in range(len(A)//2):
S+=(A[i]*2)
return S
B = [10,11,12,30,32,34,35,38,40,2]
C = Change(B)
print('Output is',C)
17. What is the difference between logical error and run-time error? Give a suitable
example of each.
18. Rewrite the following code in Python after removing all syntax error(s). Underline
each correction done in the code.
Val = 32
for K in range(20:32):
if K>25
print K*Val
Else:
PRINT K+ValNumber
19. Find and write the output of the following Python code :
Txt="Some2Thing"
STxt=""
def fibo(n)
a=1,b=1
print(a,b)
for i in range(2,n1+1):
c=a+b
print(c)
a=c
b=c
CBSE="##ANNUAL Examination2023##"
Write the output of: print(CBSE[::-3])
print(S.replace('2','2+1')[::-2])
for i in D.values():
print(i,end=' ')
def change():
Text1="CBSE 2021"
Text2="#"
I=0
while I<len(Text1) :
Val = int(Text1[I])
Val = Val + 1
Text2=Text2 + str(Val)
Text2=Text2 + (Text1[I+1])
else :
Text2=Text2 + "*"
I=I+1
print(Text2)
change()
7. What output will be generated when the following Python code is executed?
11. 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.
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]
12. Predict the output of the code given below:
def convert(Old):
l=len(Old)
New=" "
for i in range(0,1):
if Old[i].isupper():
New=New+Old[i].lower()
elif Old[i].islower():
New=New+Old[i].upper()
elif Old[i].isdigit():
New=New+"*"
else: New=New+"%"
return New
Older="InDIa@2022"
Newer=Convert(Older)
print("New String is: ", Newer)
Revision Tour - Worksheet – 1 – 3 Marks Page 5
13. Write a function INDEX_LIST(L), where L is the list of elements passed as argument
to the function. The function returns another list named ‘indexList’ that stores the
indices of all Elements of L which has a even unit place digit.
For example: If L contains [12,4,15,11,9,56]
The indexList will have - [0,1,5]
14. Find and write the output of the following Python code:
def makenew(mystr):
newstr = " "
count = 0
for i in mystr:
if count%2 !=0:
newstr = newstr+str(count)
else:
ifi.islower():
newstr = newstr+i.upper()
else:
newstr = newstr+i
count +=1
newstr = newstr+mystr[:1]
print("The new string is :", newstr)
makenew("sTUdeNT")
15. Write a Python function to sum all the numbers in a list.
Sample List : [8, 2, 3, 0, 7]
Expected Output : 20
16. Write a function listchange(Arr)in Python, which accepts a Arr of numbers , the
function will replace the even number byvalue 10 and multiply odd number by 5 .
Sample Input Data of the list is:
a=[10,20,23,45]
output : [10, 10, 115, 225]
17. Write a function in REP which accepts a list of integers and its size as
arguments and replaces elements having even values with its half and elements
having odd values with twice its value .
eg: if the list contains
if Exam[i].isspace():
Res=Res+'-'
elif Exam[i].isdigit():
Res=Res+'$'
elif Exam[i].isupper():
Res=Res+Exam[i-1]
elif Exam[i].islower():
Res=Res+Exam[i].upper()
else:
Res=Res+"*"
print(Res)
20. What will be the output of the following python code.
def change(msg):
if not msg[i].isalpha():
ifmsg[i] == ‘ ’:
else:
ifmsg[i].isupper():
returnnew_msg
Which of the following statements should be given in the blank for #Missing Statement,
if the output produced is 110?
a. global a b. global b=100 c. global b d. global a=100
8. Write the output of the following Python code :
def Update(X=10):
X += 15
print('X = ', X)
X=20
Update()
print('X = ', X)
9. Which of the following statement(s) would give an error after executing the following
code?
def prod (int a): #Statement 1
d=a*a #Statement 2
print(d) #Statement 3
return prod #Statement 4
(a) Statement 1 and Statement 2 (c) Statement 1 and Statement 4
(b) Statement 1 and Statement 3 (d) Statement 2 and Statement 4
10. Assertion (A) :- A return statement returns a value as well as the control from a
function.
Reasoning (R) :- It is compulsory for all functions to have a return statement.
11. Assertion(A):-If the arguments in function call statement match the Number and
order of arguments as defined in the function definition, such arguments are called
positional arguments.
Reasoning(R):-During a function call, the argument list positional argument(s) must
occur after the default arguments.
1. What do you understand by local and global scope of variables? How can you access a
global variable inside the function, if function has a variable with same name.
2. What will be the output of the following code?
value = 50
def display(N):
global value
value = 25
if N%7==0:
value = value + N
else:
value = value - N
print(value, end="#")
display(20)
print(value)
3. Predict the output of the Python code given below:
def Diff(N1,N2):
if N1>N2:
return N1-N2
else:
return N2-N1
NUM= [10,23,14,54,32]
for CNT in range (4,0,-1):
A=NUM[CNT]
B=NUM[CNT-1]
print(Diff(A,B),'#', end=' ')
4. 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
defprintMe(q,r=2):
p=r+q**3
print(p)
#main-code
a=10
b=5
printMe(a,b)
printMe(r=4,q=2)
1. Write a function LShift(Arr,n) in Python, which accepts a list Arr of numbers and n is
a numeric value by which all elements of the list are shifted to left.
Sample Input Data of the list Arr= [ 10,20,30,40,12,11], n=2
Output
Arr = [30,40,12,11,10,20]
2. Find and write the output of the following python code:
def Change(P ,Q=30):
P=P+Q
Q=P-Q
print( P,"#",Q)
return (P)
R=150
S=100
R=Change(R,S)
print(R,"#",S)
S=Change(S)
print(R,"#",S)
3. Write a function INDEX_LIST(L), where L is the list of elements passed as argument to
the function. The function returns another list named ‘indexList’ that stores the indices
of all Non-Zero Elements of L.
For example: If L contains [12,4,0,11,0,56]
The indexList will have - [0,1,3,5]
4. Find and write the output of the following Python code :
def Call(P=40,Q=20):
P=P+Q
Q=P–Q
print(P,'@',Q)
return
R=200
S=100
R=Call(R,S)
Function - Worksheet – 1 - 3 Marks Page 1
print (R,'@',S)
S=Call(S)
print(R,'@',S)
5. Write the definition of a function Sum3(L) in Python, which accepts a list L of integers
and displays the sum of all such integers from the list L which end with the digit 3.
For example, if the list L is passed [ 123, 10, 13, 15, 23]
then the function should display the sum of 123, 13, 23, i.e. 159 as follows :
Sum of integers ending with digit 3 = 159
6. Find and write the output of the following Python code :
def Compute(A,B,C="*"):
for I in range(A,B+1):
if I%2==0:
print(I,C)
else:
print(I,"@")
print (" " )
Compute(10,14)
Compute(25,29,"#")
Compute(5,10)
7.Write definition of a method/function TenSum(SCORES)to find and display sum of
those scores which are less than 500 and ending with 0.
For example, If the SCORES contain [150,206,370,110,920,530,501,120]
The function should display
Ten Sum: 640
8. Write definition of a method/function NotLess(PRICE, LowPrice) to count and display
number of values of PRICE, which are not less than LowPrice.
For Example :
If the PRICE contains [100,120,103,180,162,113] and LowPrice contains 115
The function should display: 2 Prices are not less than 115
9. Write a function NEW_LIST(L),where L is the list of integers passed as that stores
all the 4 digits integers present in L.
For example:
If L contains[123,3454,0,87511,8612,5678,66]
The New List will have[3454,8612,5678]
1. Write a function countINDIA() which read a text file ‘myfile.txt’ and print the
frequency
of the words ‘India’ in it (ignoring case of the word).
Example: If the file content is as follows:
INDIA is my country.
I live in India. India has many states.
The countIndia() function should display the output as:
Frequency of India is 3
2. 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 and upper case).
Example:
If the file content is as follows:
INDIA is my country. I live in India. India has many states.
The countVowel() function should display the output as:
Total number of vowels are : 20
3. A pre-existing text file data.txt has some words written in it. Write a python function
displaywords() that will print all the words that are having length greater than 3.
Example: For the file content:
A man always wants to strive higher in his life
He wants to be perfect.
The output after executing displayword() will be:
Always wants strive higher life wants perfect
4. A pre-existing text file info.txt has some text written in it. Write a python function
countvowel() that reads the contents of the file and counts the occurrence of
vowels(A,E,I,O,U) in the file.
5. Write a function COUNT_AND( ) in Python to read the text file “STORY.TXT” and count
the number of times “AND” occurs in the file. (include AND/and/And in the counting)
7. What is the advantage of using a csv file for permanent storage? Write a Program in
Python that defines and calls the following user defined functions:
(i) ADD() – To accept and add data of an employee to a CSV file ‘record.csv’. Each record
consists of a list with field elements as empid, name and mobile to store employee id,
employee name and employee salary respectively.
(ii) COUNTR() – To count the number of records present in the CSV file named
‘record.csv’.
8. Give any one point of difference between a binary file and a csv file. Write a Program
in Python that defines and calls the following user defined functions:
(i) add() – To accept and add data of an employee to a CSV file ‘furdata.csv’. Each record
consists of a list with field elements as fid, fname and fprice to store furniture id,
furniture name and furniture price respectively.
(ii) search()- To display the records of the furniture whose price is more than 10000.
9. Write a function in Phyton to read lines from a text file visiors.txt, and display only
those lines, which are starting with an alphabet 'P'.
If the contents of file is :
Visitors from various cities are coming here.
Particularly, they want to visit the museum.
Looking to learn more history about countries with their cultures.
The output should be:
Particularly, they want to visit the museum
10. Write a method in Python to read lines from a text file book.txt, to find and display
the occurrence of the word 'are'.
For example, if the content of the file is:
Books are referred to as a man’s best friend. They are very beneficial for mankind and
have helped it evolve. Books leave a deep impact on us and are responsible for uplifting
our mood.
The output should be
3
1.
_________________ #Statement 1
headings = ['Country','Capital','Population']
data = [['India', 'Delhi',130],['USA','Washington DC',50],[Japan,Tokyo,2]]
f = open('country.csv','w', newline="")
csvwriter = csv.writer(f)
csvwriter.writerow(headings) ________________ #Statement 2
f.close()
f = open('country.csv','r')
csvreader = csv.reader(f)
head = _________________ #Statement 3
print(head)
for x in __________: #Statement 4
ifint(x[2])>50:
print(x)
a) Statement 1 – Write the python statement that will allow Sudheer work with csv files.
b) Statement 2 – Write a python statement that will write the list containing the data
available as a nested list in the csv file
c) Statement 3 – Write a python statement to read the header row in to the head object.
d) Statement 4 – Write the object that contains the data that has been read from the file.
3.Anuj Kumar of class 12 is writing a program to create a CSV file “user.csv” which will
contain user name and password for some entries. He has written thefollowing code. As
a programmer, help him to successfully execute the giventask.
import _____________ # Line 1
def addCsvFile(UserName,PassWord): # to write / add data into the CSV file
f=open(' user.csv','________') # Line 2
newFileWriter = csv.writer(f)
newFileWriter.writerow([UserName,PassWord])
f.close() #csv file reading code
def readCsvFile(): # to read data from CSV file
with open(' user.csv','r') as newFile:
addCsvFile(“Arjun”,”123@456”)
addCsvFile(“Arunima”,”aru@nima”)
addCsvFile(“Frieda”,”myname@FRD”)
(a) Name the module he should import in Line 1.
(b) In which mode, Anuj should open the file to add data into the file
(c) Fill in the blank in Line 3 to read the data from a csv file.
(d) Fill in the blank in Line 4 to close the file.
4. Mr. Deepak is a Python programmer. He has written a code and created a binary
file “MyFile.dat” with empid, ename and salary. The file contains 15 records.
He now has to update a record based on the employee id entered by the user and
update the salary. The updated record is then to be written in the file “temp.dat”. The
records which are not to be updated also have to be written to the file “temp.dat”. If
the employee id is not found, an appropriate message should to be displayed.
As a Python expert, help him to complete the following code based on the
requirement given above:
import _______ #Statement 1
def update_rec():
rec={}
fin=open("MyFile.dat","rb")
fout=open("_____________") #Statement 2
found=False
eid=int(input("Enter employee id to update salary : "))
while True:
try:
rec=______________ #Statement 3
if rec["empid"]==eid:
found=True
rec["salary"]=int(input("Enter new salary : "))
pickle.____________ #Statement 4
def GetStudents():
Total=0
Countrec=0
Countabove75=0
with open("STUDENT.DAT","rb") as F:
while True:
try:
___________________ #statement 3 to read from the file
Countrec+=1
Total+=R[2]
if R[2] > 75:
print(R[1], " has percent =",R[2])
Countabove75+=1
except:
break
if Countabove75==0:
print("No student has percentage more than 75")
print("average percent of class = ",_____________) #statement 4
AddStudents()
GetStudents()
(i) Which of the following commands is used to open the file “STUDENT.DAT” for writing
only in binary format? (marked as #1 in the Python code)
(ii) Which of the following commands is used to write the list L into the binary file,
STUDENT.DAT? (marked as #2 in the Python code)
(iii) Which of the following commands is used to read each record from the binary file
STUDENT.DAT? (marked as #3 in the Python code)
19. Gupta is writing a program to create a csv file “employee.csv” which will
contain user name and password for department entries. He has written the
following code . As a programmer, help him to successfully execute the given
task.
import ---------------- #statement 1
def add_emp(username,password):
f=open(‘employee.csv’, ’----------‘) # statement 2
content=csv.writer(f)
content.writerow([username,password])
f.close()
def read_emp( ):
with open (‘employee.csv’,’r’) as file:
content_reader=csv.-------------------(file) # statement 3
for row in content_reader:
print(row[0],row[1])
file.close( )
add_emp(‘mohan’,’emp123#’)
add_emp(‘ravi’,’emp456#’)
read_emp() #statement 4
i) Name the module he should import in statement 1
ii) In which mode , Gupta should open the file to add record in to the file ? (statement 2)
iii) Fill in the blank in statement 3 to read the record from a csv file
iv) What output will he obtain while executing statement 4 ?
1.
2.
2. Write the full form of ‘CSV’. What is the default delimiter of csv files? The scores and ranks of
three students of a school level programming competition is given as: [‘Name’, ‘Marks’, ‘Rank’]
[‘Sheela’, 450, 1]
[‘Rohan’, 300, 2]
[‘Akash’, 260, 3]
Write a program to do the following:
(i) Create a csv file (results.csv) and write the above data into it.
(ii) To display all the records present in the CSV file named ‘results.csv’
OR
What does csv.writer object do?
3. Rohan is making a software on “Countries & their Capitals” in which various records are to
be stored/retrieved in CAPITAL.CSV data file. It consists some records(Country & Capital).
Help him to define and call the following user defined functions:
(i) AddNewRec(Country,Capital) – To accept and add the records to a CSV file
“CAPITAL.CSV”. Each record consists of a list with field elements as Country and
Capital to store country name and capital name respectively.
(ii) ShowRec() – To display all the records present in the CSV file named ‘CAPITAL.CSV’
Write the following functions in python accommodate the data and manipulate it.
a) A function insert() that creates the data.dat file in your system and writes the three
dictionaries.
b) A function() read() that reads the data from the binary file and displays the dictionaries whose
age is 16.
5.(a) What does CSV stand for?
(b) Write a Program in Python that defines and calls the following user defined functions:
(i) InsertRow() – To accept and insert data of an student to a CSV file ‘class.csv’. Each record
consists of a list with field elements as rollno, name and marks to store roll number, student’s
name and marks respectively.
(ii) COUNTD() – To count and return the number of students who scored marks greater than 75
in the CSV file named ‘class.csv’
6. Dhirendra is a programmer, who has recently been given a task to write a python code to
perform the following CSV file operations with the help of two user defined functions/modules:
a. CSVOpen() : to create a CSV file called BOOKS.CSV in append mode containing information of
books – Title, Author and Price.
b. CSVRead() : to display the records from the CSV file called BOOKS.CSV where the field title
starts with 'R'. He has succeeded in writing partial code and has missed out certain statements,
so he has left certain queries in comment lines.
importcsv
def CSVOpen():
with open('books.csv','_____',newline='') as csvf: #Statement-1
cw=_____________#Statement-2
__________________#Statement-3
cw.writerow(['Rapunzel','Jack',300])
cw.writerow(['Barbie','Doll',900])
cw.writerow(['Johnny','Jane',280])
def CSVRead():
try:
with open('books.csv','r') as csvf:
cr=_________________#Statement-4
for r in cr: if : #Statement-5
addCsvFile(“Aman”,”123@456”)
addCsvFile(“Vijay”,”aru@nima”)
addCsvFile(“Raju”,”myname@FRD”)
readCsvFile()
(i) Give Name of the module he should import in Line 1.
(ii) In which mode, Vijay should open the file to add data into the file in Line2.
(iii) Complete the Line 3 to read the data from csv file and Line 4 to close the file
14. What is the significance of a delimiter symbol in a csv file? Write a Program in Python that
defines and calls the following user defined functions:
(i) ADD_CONT() – To accept and add data of a contact to a CSV file ‘address.csv’. Each record
consists of a list with field elements as contId, cname and cmobile to store contact id, contact
name and contact number respectively.
(ii) COUNT_CONT() – To count the number of records present in the CSV file named ‘address.csv’
15. How csv file is different from a binary file? Write a Program in Python that defines and calls
the following user defined functions:
(i) save() – To accept and add data of watches to a CSV file ‘watchdata.csv’. Each record consists
of a list with field elements as watchid, wname and wprice to store watch id, watch name and
watch price respectively.
(ii) search()- To display the records of the watch whose price is more than 6000.
16. Vaishanavi is a budding Python programmer. She has written a code and created a binary
file phonebook.dat with contactNo, name and blocked [ Y/ N ]. The file contains 10 records as a
dictionary like {‘contactNo’ : 32344455 , ‘name’: ‘kamalkant’ ,’blocked’ : “Y” }
She now wants to shift all the records which have blocked = ‘Y’ status from phonebook.dat to a
binary file blocked.dat also all records which have blocked = ‘N’ status from phonebook.dat to
unblocked.dat. She also wants to keep count and print the total number of blocked and
unblocked records. As a Python expert, help her to complete the following code based on the
requirement given above:
import _____________ #Statement 1
def shift_contact( ):
fin = open(“phonebook.dat”,’rb’)
fblock = open( ___________________ ) #Statement 2
funblock = open( ___________________ ) #Statement 3
while True :
try: rec = __________________ # Statement 4
25. In a try-except block, if an exception occurs but it is not handled by any except
clause, what happens?
a) The program terminates b) The exception is ignored
c) The program continues to execute normally d) None of the above
10. Write two points of difference between ALTER and UPDATE command in SQL.
11. Categorize the following commands as DDL or DML: DROP, DELETE, SELECT,
ALTER
12. Explain the use of primary key in a relational database system? Give example to
support your answer?
13. Define Tuple and Attribute with appropriate example.
14. Explain the use of “Primary key in a Relational Database Management System.
Give example to support your answer
15. Differentiate between DDL and DML?
16. Write the main difference between INSERT and UPDATE Commands in SQL
17. Differentiate between ‘WHERE’ clause and ‘HAVING’ clause in MySQL with
appropriate example.
18. Differentiate between DELETE and DROP keywords used in MySQL,giving suitable
example for each
19. Define Primary Key of a relation in SQL. Give an Example using a dummy table.
20. Consider the following Python code is written to access the record of CODE passed to
function: Complete the missing statements:
def Search(eno):
#Assume basic setup import, connection and cursor is created
query="select * from emp where empno=________".format(eno)
mycursor.execute(query)
results = mycursor._________
print(results)
21. What is a cursor and how to create it in Python SQL connectivity?
22. What is Degree and Cardinality in relational table?
23. Answer the following :
(i) Select BRAND_NAME, FLAVOUR from CHIPS where PRICE <> 10;
(ii) Select * from CHIPS where FLAVOUR=”TOMATO” and PRICE > 20;
(iii) Select BRAND_NAME from CHIPS where price > 15 and QUANTITY < 15;
(iv) Select count( distinct (BRAND_NAME)) from CHIPS;
(v) Select price , price *1.5 from CHIPS where FLAVOUR = “PUDINA”;
(vi) Select distinct (BRAND_NAME) from CHIPS order by BRAND_NAME desc;
2.(A) Consider the following tables BOOKS and ISSUED in a database named “LIBRARY”.
WriteSQL commands for the statements (i) to (iv).
(i) Display book name and author name and price of computer type books.
(ii) To increase the price of all history books by Rs 50.
(iii) Show the details of all books in ascending order of their prices.
(iv) To display book id, book name and quantity issued for all books which have been
issued.
(B)Write the command to view all tables in a database.
4. Write the outputs of the SQL queries (i) to (iii) based on the relations Teacher and
Posting given below:
12. a. Consider the following tables ACTIVITY and COACH.Write SQL commands for the
statements (i) to (iv) and give the The outputs for the SQL queries (v) to (viii)
Table: Activity
(i) To display the name of all activities with their Acodes in descending order.
(ii) To display sum of PrizeMoney for each of the number of participants groupings (as
shown in column ParticipantsNum 10,12,16)
(iii) To display the coach’s name and ACodes in ascending order of ACode from the table
COACH.
(iv) To display the content of the Activity table whose ScheduleDate is earlier than
01/01/2004 in ascending order of ParticipantsNum.
What is the degree and cardinality of table Employee, if it contains only the given data?
Which field fields is/are the most suitable to be the Primary key if the data shown above
is only the partial data?
(b) Write the output of the queries (i) to (iv) based on the table Employee:
(i) select name, project from employee order by project;
(ii) select name, salary from employee where doj like'2015%';
(iii)select name, salary from employee where salary between 100000 and 200000;
(iv) select min(doj), max(dob) from employee;
16. (a) Write the outputs of the SQL queries (i) to (iv) based on the relations Projects and
Employee given below:
i.SELECT Designation COUNT (*) FROM Admin GROUP BY Designation HAVING COUNT
(*) <2:
ii.SELECT max (EXPERIENCE) FROM SCHOOL;
iii. .SELECT TEACHER FROM SCHOOL WHERE EXPERIENCE >12 ORDER BY
TEACHER;
iv.SELECT COUNT (*), GENDER FROM ADMIN GROUP BY GENDER;
18. (a)Sonal needs to display name of teachers, who have “0” as the third character in
their name. She wrote the following query.
SELECT NAME FROM TEACHER WHERE NAME = “$$0?”;
But the query is’nt producing the result. Identify the problem.
(b)Write output for (i) & (iv) based on table COMPANY and CUSTOMER
22. (a) Write the outputs of the SQL queries (i) to (iv) based on the relations SCHOOL
and ADMIN given below:
Table: School Table: Admin
The Following program code is used to increase the salary of Trainer SUNAINA by 2000.
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is system
The table exists in a MYSQL database named Admin.
Write the following missing statements to complete the code:
Statement 1 – to form the cursor object
Statement 2 – to execute the command that inserts the record in the table Student.
Statement 3- to add the record permanently in the database
import mysql.connector as mydb
mycon = mydb.connect (host = “localhost”, user = “root”, passwd = “system”, database =
“Admin”)
cursor = _______________ #Statement 1
sql = “UPDATE TRAINER SET SALARY = SALARY + 2000 WHERE TNAME = ‘SUNAINA’”
cursor. _______________ #Statement 2
_______________ #Statement 3
mycon.close( )
a) Write a query to display the passenger, source, model and price for all bookings whose
destination is KOL.
b) Identify the column acting as foreign key and the table name where it is present in the
given example.
5. Sumitra wants to write a program to connect to MySQL database using python and
increase the age of all the students who are studying in class 11 by 2 years.
Since she had little understanding of the coding, she left a few blank spaces in her code.
Now help her to complete the code by suggesting correct coding for statements 1, 2 and
3.
import ________________ as myc # Statement 1
con = myc.connect(host="locahost", user="root", passwd="", database="mydb")
mycursor = __________________ #Statement 2
sql = "UPDATE student SET age=age+2 WHERE class='XI'"
(i) Display the Trainer Name, City & Salary in descending order of their Hiredate.
(ii) To display the TNAME and CITY of Trainer who joined the Institute in the month of
December 2001.
(iii) To display TNAME, HIREDATE, CNAME, STARTDATE from tables TRAINER and
COURSE of all those courses whose FEES is less than or equal to 10000.
(iv) To display number of Trainers from each city.
OR
(iv) To display the Trainer ID and Name of the trainer who are not belongs to ‘Mumbai’
and ‘DELHI’
8. A company stores the records of motorbikes sold in January, February, March and
April months in MOTOR table as shown below:
def Count_Rec(Author):
fobj = open("book.dat","rb")
num = 0
try:
while True:
rec = pickle._______________ #statement4
if Author == rec[2]:
num=num+1
1. Identify the Primay Key from the given table with justification of your answer.
2. If three more records are added and 2 more columns are added, find the degree
and cardinality of the table.
3. (i) Write SQL command to insert one more data/record to the table
(ii) Increase the price of furniture by 1000, where discount is given more than 10.
OR (Option for part 3 only)
3. Write the statements to:
(a) Delete the record of furniture whose price is less than 20000.
(b) Add a column WOOD varchar with 20 characters.
11. Mayank creates a table RESULT with a set of records to maintain the marks secured
by students in sub1, sub2, sub3 and their GRADE. After creation of the table, he has
entered data of 7 students in the table.
Table : RESULT
(i) Display the Trainer Name, City & Salary in descending order of their Hiredate.
(ii) To display the TNAME and CITY of Trainer who joined the Institute in the month of
December 2001.
(iii) To display TNAME, HIREDATE, CNAME, STARTDATE from tables TRAINER and
COURSE of all those courses whose FEES is less than or equal to 10000.
(iv) To display number of Trainers from each city.
(v) To display the Trainer ID and Name of the trainer who are not belongs to ‘Mumbai’
and ‘DELHI’
2. Write SQL queries for (i) to (v), which are based on the table: SCHOOL and ADMIN
TABLE: SCHOOL TABLE: ADMIN
3.
Identify the primary key in the table. Write query for the following
ii. Find average salary in the table.
iii. Display number of records for each individual designation.
iv. Display number of records along with sum of salaries for each individual designation
where number of records are more than 1.
v. What is the degree and cardinality of the relation Employee?
4. Write SQL commands for the following queries (i) to (v) on the basis of relation Mobile
Master and Mobile Stock.
i) To display details of all the items in the Store table in descending order of LastBuy.
ii) To display Itemno and item name of those items from store table whose rate is more
than 15 rupees.
iii) To display the details of those items whose supplier code is 22 or Quantity in store is
more than 110 from the table Store.
iv) To display minimum rate of items for each Supplier individually as per Scode from
the table Store.
6. Write SQL commands for the following queries (i) to (v) based on the relations
TRAINER & COURSE given below:
(i) Display all details of Trainers who are living in city CHENNAI.
(ii) Display the Trainer Name, City & Salary in descending order of their Hiredate.
(iii) Count & Display the number of Trainers in each city.
(iv) Display the Course details which have Fees more than 12000 and name ends with
‘A’. (v) Display the Trainer Name & Course Name from both tables where Course Fees is
less than 10000.
7. Write SQL commands for the queries (i) to (iii) and output for (iv) & (v) based on a
table COMPANY and CUSTOMER .
8. Write SQL Commands for the following queries based on the relations PRODUCT and
CLIENT given below.
(i) To display the ClientName and City of all Mumbai- and Delhi-based clients in Client
table.
(ii) Increase the price of all the products in Product table by 10%.
(iii) To display the ProductName, Manufacturer, ExpiryDate of all the products that
expired on or before ‘2010-12-31’.
9. Consider the following tables Sender and Recipient. Write SQL commands for the
statements (a) to (c) and give the outputs for SQL queries (d) to (e).
TABLE; ISSUED
TABLE: DEALER
13. Anmol maintains that database of Medicines for his pharmacy using SQL to store
the data. The structure of the table PHARMA for the purpose is as follows :
Name of the table – PHARMA
The attributes of PHARMA are as follows :
MID - numeric
DBMS Worksheet – 1 - 5 Marks Page 8
MNAME - character of size 20
PRICE - numeric
UNITS - numeric
EXPIRY - date
Table : PHARMA
Write the SQL command which Anmol should execute to perform the required
task.
(d) Anmol wants to change the name of the attribute UNITS to QUANTITY in the table
PHARMA. Which of the following commands will he use for the purpose ?
(i) UPDATE (ii) DROP TABLE
(iii) CREATE TABLE (iv) ALTER TABLE
(e) Now Anmol wants to increase the PRICE of all medicines by 5. Which of the
following commands will he use for the purpose ?
(i) UPDATE SET (ii) INCREASE BY
(iii) ALTER TABLE (iv) INSERT INTO
(a) To display all information about the CUSTOMERs whose NAME starts with 'A'.
(b) To display the NAME and BALANCE of Female CUSTOMERs (with GENDER as 'F')
whose TRANSACTION Date (TDATE) is in the year 2019.
(c) To display the total number of CUSTOMERs for each GENDER.
(d) To display the CUSTOMER NAME and BALANCE in ascending order of GENDER.
(e) To display CUSTOMER NAME and their respective INTEREST for all CUSTOMERs
where INTEREST is calculated as 8% of BALANCE.
15. i) What do you mean by a Primary key in RDBMS ?
ii) Complete the following database connectivity program by writing the missing
statements and performing the given query
import ------------------- as mysql # statement 1
con=mysql. ---------(host=’localhost’,user=’root’,passwd=’123’ ,
database=’student’) # statement 2
cursor=con.cursor( )
cursor.execute(--------------------------------) # statement 3
data=cursor. ----------------------------------- # statement 4
for rec in data:
print(rec)
16. (i) What is the difference between a Candidate Key and an Alternate Key.
(ii) Virat has created a table named TRAVELS in MySQL:
Tour_ID – string
Destination – String
Geo_Cond– String
Distance – integer (In KM)
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is bharat
The table TRAVELS exists in a MYSQL database named TOUR.
The details Tour_ID, Destination, Geo_Cond and Distance are to be accepted
from the user.
Virat wants to display All Records of TRAVELS relation whose Geographical conditionis
hilly area and distance less than 1000 KM. Help Virat to write program in python.
OR
17. (i) How many candidate key and primary key a table can have in a Database?
(ii) Manish wants to write a program in Python to create the following table
named “EMP” in MYSQL database, ORGANISATION:
Eno (Employee No )- integer , Ename (Employee Name) - string
Edept (Employee Department)-string, Sal (salary)-integer
Note the following to establish connectivity between Python and MySQL:
Username – root , Password – admin , Host - localhost
The values of fields eno, ename, edept and Sal has to be accepted from the
user. Help Manish to write the program in Python to insert record in the above
table..
OR
(i) Differentiate between degree & cardinality key in RDBMS?
(iii) Vihaan wants to write a program in Python to create the following table
named “EMP” in MYSQL database, ORGANISATION:
Eno (Employee No )- integer , Ename (Employee Name) - string
Edept (Employee Department)-string, Sal (salary)-integer
Note the following to establish connectivity between Python and MySQL:
Username – root , Password – admin , Host - localhost
Help Vihaan to write the program in Python to Alter the above table with new
1. Write two points of difference between Bus topology and star topology.
2. Write two points of difference between XML and HTML.
3. Write the full forms of the following:
(A) (i) HTTP (ii) FTP
(B) What is the use of TELNET?
4. Mention two differences between a Hub and a switch in networking.
5. Mention one advantage and one disadvantage of Star Topology.
6. a) Expand the following abbreviations: i) URL ii) TCP
b) What is the use of VoIP?
7. Write two points of difference between Web Page and Web site.
8. (a) Write the full forms of the following: (i) SMTP (ii) PPP
(b) What is the use of TELNET?
9. Write two advantages and two disadvantages of circuit switching
10. Differentiate between Web server and web browser. Write any two popular web
browsers.
11. (a) Write the full forms of the following: (i) FTP (ii) HTTPS
(b)Name the protocols which are used for sending and receiving emails?
12. Write two points of difference between LAN & WAN.
13. Write two points of difference between XML and HTML.
14. a. Expand the following terms: SMTP, FTP
b. What do you mean by modem?
15. Write two differences between Coaxial and Fiber transmission media.
16. Write components of data communication.
17. (a) Write the full forms of the following: (i) FTP (ii) MAC
(b) What is the use of TELNET?
18. Name two top level domain names with their area of application.
19. (a) Write the full forms of the following: (i) VoIP (ii) IMAP
(b) Name the communication medium which is used for WiFi.
20. Write two points of difference between LAN and MAN.
21. Write two points of difference between HTML and XML.
Computer Networks Worksheet – 1 - 2 Marks Page 1
22. (a) Expand the following abbreviations:
i)POP ii)HTTPS
(b) What is a URL?
23. Give difference between Video Conferencing and Chatting
24. Write two points of difference between Message Switching and Packet Switching
25. (a) Write the full forms of the following: (i)GSM (ii)XML
(b) What is the use of Modem?
1. 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:
Distance between the blocks and number of computers in each block are as given below:
(i) Suggest the most suitable block to host the server. Justify your answer.
(ii) Draw the cable layout (Block to Block) to economically connect various blocks within
the Delhi campus of International Bank.
(iii) Suggest the placement of 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.
(i) Suggest the most appropriate block/location to house the SERVER in the
Surajpurcenter (out of the 3 blocks) to get the best and effective connectivity. Justify
your answer. (ii) Suggest why should a firewall be installed at the SurajpurCenter?
(iii) Suggest the best wired medium and draw the cable layout (Block to Block) to most
efficiently connect various blocks within the SurajpurCenter.
(iv) Suggest the placement of the following devices with appropriate reasons:
a) Switch/Hub b) Router
(v) Suggest the best possible way to provide wireless connectivity between
SurajpurCenter and Raipur Center.
8. 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. 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.
10. 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.
11. “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:
(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.
(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
Note: * In Villages, there are community centres, 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.
1. 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.
2. Suggest the best wired medium and draw the cable layout (location to location) to
efficiently connect various locations within the YHUB.
3. Which hardware device will you suggest to connect all the computers within each
location of YHUB?
4. Which server/protocol will be most helpful to conduct live interaction of Experts from
Head office and people at YHUB locations?
Computers in each building are networked but buildings are not networked so far. The
Company has now decided to connect building also.
(i) Suggest a cable layout for connecting the buildings
(ii) Do you think anywhere Repeaters required in the campus? Why
(iii) The company wants to link this office to their head office at Delhi
(a) Which type of transmission medium is appropriate for such a link?
(b) What type of network would this connection result into?
(iv) Where server is to be installed? Why?
(v) Suggest the wired Transmission Media used to connect all buildings efficiently.