Cs Paper-4
Cs Paper-4
Cs Paper-4
c
II. c
III. a load(f)
IV. d. rec[0]==1
293 | P a g e
a)Hello b) Hello Friend c) 'sdneirF olleH' d) Friend
6 Which of the following function is used to write data in binary mode? 1
a) write ( ) b) output ( ) c) dump ( ) d) send ( )
7 Suppose a tuple T1 is declared as T1 = (10, 20, 30, 40, 50) which of the following is 1
incorrect?
a)print(T[1]) b) T[2] = -29 c) print(max(T)) d) print(len(T))
8 What will be output of following: 1
d = {1 : “SUM”, 2 : “DIFF”, 3 : “PROD”}
for i in d:
print (i)
a)1 b) SUM c) 1 d) 3
2 DIFF SUM SUM
3 PROD 2 3
DIFF DIFF
3 3
PROD PROD
297 | P a g e
The stack should contain
["20221017","Guru","9988779988"]
["20221018","Ragunath","9977889988"]
["20221020","Priya","9966557864"]
299 | P a g e
print("Data Added successfully")
OR
a) Predict the output of the code given below:
str1=input ("Enter a string: ")
str2="aAeEiIoOuU"
v,c=0,0
for i in str1:
if i in str2:
v+=1
else:
c+=1
print ("The given string contains { } vowels and { } consonants".format(v,c))
b) The code given below reads the following record from the table named employee and
displays
only those records who have salary greater than 65000:
Empno – integer
Name – string
Dept – string
Salary – integer
Note the following to establish connectivity between Python and MYSQL:
❖ Username is host
❖ Password is root
❖ The table exists in a MYSQL database named company.
Write the following missing statements to complete the code:
Statement 1 – to form the cursor object
Statement 2 – to execute the query that extracts records of those employee whose salary
are greater
than 65000.
Statement 3- to read the complete result of the query (records whose salary are greater
than 65000) into the object named data, from the table employee in the database.
import mysql.connector as mysql
def sql_data():
con1=mysql.connect(host="localhost",user="host",
password="root", database="company")
mycursor=_______________ #Statement 1
print("Employee with salary greater than 65000 are : ")
_________________________ #Statement 2
data=__________________ #Statement 3
for i in data:
print(i)
print()
300 | P a g e
3 What are the merits of using a csv file for storage? 5
3 Write a Program in Python that defines and calls the following user defined functions:
(i) ADD() – To accept and add data of an Library to a CSV file ‘books.csv’. Each record
consists of a list with field elements as bno, name,Author and type to store Book number
id, Book name, Author Name and Type of Book respectively.
OR
Give any one point of difference between a text file and a csv file.
Write a Program in Python that defines and calls the following user defined functions:
(i) update() – To accept and update data of a student to a CSV file ‘mark.csv’. Each
record consists of a list with field elements as sid, sname and sclass to store student id,
student name and student class respectively.
SECTION-E
3 Write SQL commands for the following queries based on the relation Teacher given
4 below:
4
Table: Teacher
N Ag Departme Date_of_jo Salar Se
o Name e nt in y x
1200
1 Jugal 34 Computer 10-01-1997 0 M
Sharmil 2000
2 a 31 History 24-03-1998 0 F
Sandee 3000
3 p 32 Maths 12-12-1996 0 M
Sangeet 4000
4 a 35 History 01-07-1999 0 F
2500
5 Rakesh 42 Maths 05-09-1997 0 M
3000
6 Shyam 50 History 27-06-1998 0 M
Shiv 2100
7 Om 44 Computer 25-02-1997 0 M
Shalak 2000
8 ha 33 Maths 31-07-1997 0 F
(i) To show all information about the teacher of Computer department.
(ii) To list the names of all teachers with their date of joining in descending order.
(iii) Write the statements to
a) Delete the record of teacher age greater than 45
b)Increase the salary of teachers by 15% whose department is history
OR
301 | P a g e
a) To count the number of teachers with age less than 35
b)Add column QUALIFICATION in the table with datatype as varchar with 50
characters.
3 Mr.Mathew is a Python programmer. who has recently joined the company and given a 4
5 task to write a python code to perform update operation in binary file(stud.dat)which
contain admno(Admission no) and fee(Fee paid by student).
He has succeeded in writing partial code and has missed out certain statement ,you as an
expect of python have to provide the missing statements.
import _______ #Statement 1
St={}
Flag=0
File=open("____________","rb+) #Statement 2
Search=int(input("Enter Admission number whose fee is to be updated :"))
Amt=int(input("How much to be incresed:"))
try:
while True:
Try:
Pos=file.tell()
St=pickle.load(file)
If st['admno']==search:
st['fee']+=amt
file._________(pos) #Statement 3
pickle.__________(st.file) #Statement 4
print("Record Updated")
flag=1
expect EOFError:
if flag=0:
print("Record not found")
file.close()
(i) Which module should be imported in the program? (Statement 1)
(ii) Write the correct statement required to open binary file (Statement 2)
(iii) Which statement should be fill in Statement 3 to place the file pointer at specified position
and statement 4 used to store the data
302 | P a g e