0% found this document useful (0 votes)
15 views4 pages

CS Worksheet (An)

This document is a worksheet for Class XII-A2/A3 at Jeeva Velu International School, focusing on Computer Science and specifically on connecting Python with MySQL. It includes multiple-choice questions, coding exercises, and conceptual queries related to database operations, cursor functions, and file handling in Python. The worksheet aims to assess students' understanding of MySQL connections, data fetching, and file manipulation in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

CS Worksheet (An)

This document is a worksheet for Class XII-A2/A3 at Jeeva Velu International School, focusing on Computer Science and specifically on connecting Python with MySQL. It includes multiple-choice questions, coding exercises, and conceptual queries related to database operations, cursor functions, and file handling in Python. The worksheet aims to assess students' understanding of MySQL connections, data fetching, and file manipulation in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

JEEVA VELU INTERNATIONAL SCHOOL,

TIRUVANNAMALAI

CLASS:XII-A2/A3
SUBJECT:COMPUTER SCIENCE
WORKSHEET(AN)
1.Identify the name of connect or to establish bridge between Python and MySQL
a. mysql.connection
b. connector
c. mysql.connect
d. mysql.connector
2. In the following connection string: Identify the elements:
connect(<<1>> =127.0.0.1, <<2>> =‟ root‟, <<3>> =„admin‟)
a. <<1>>=User,<<2>>=password,<<3>=host
b. <<1>>=host,<<2>>=user,<<3>=password
c. <<1>>=host,<<2>>=password,<<3>=user
d. <<1>>=IP,<<2>>=user,<<3>=password
3. Which function of connection is used to check whether connection to mysql
is successfully done or not?
import mysql.connector as msq
con = msq.connect( #Connection String ) # Assuming all parameter required
as passed if :
print(“Connected!”)
else:
print(“Error!Not Connected”)

a. con.connected()
b. con.isconnected()
c. con.is_connected()
d. con.is_connect()
4. Which of the following component act as a container to hold all the data
returned from the query and from there we can fetch data one at a time?
a. Result Set
b. Cursor
c. Container
d. Table
5. Identify the correct statement to create cursor:
Import mysql. Connector as msq
con = msq.connect( #Connection String ) # Assuming all parameter required
as passed mycursor =

a.con.cursor()
b.con.create_cursor()
c.con.open_cursor()
d.con.get_cursor()
6. What is the difference in fetchall() and fetchone()?
7. Which attribute of cursor is used to get number of records stored in cursor
(Assuming cursor name is my cursor)?

a. mycursor.count
b. mycursor.row_count
c. mycursor.records
d. mycursor.rowcount
8. Which of the Symbols are used for passing parameterized query for execution to
cursor?

a. %
b. {}
c. $
d. Both a and b
9. Which function is used to fetch n number of records from cursor?
a. fetch()
b. fetchone()
c. fetchmany()
d. fetchall()
10. Which cursor function is used to send query to connection?
a. query()
b. execute()
c. run()
d. send()
11. Consider the information stored in the table :EMP
EMPNO ENAME DEPT SALARY
1 Alex Music 60000
2 Peter Art 67000
3 Johny We 55000
4 Rambo P & He 48000
Following python code is written to access the records of table: EMP, What will be
the output of following code:

#Assume All basic set up related to connection and cursor creation is already
done
query="select * from emp"
mycursor. execute(query)
results =
mycursor.fetchone() results
= mycursor.fetchone()
results =
mycursor.fetchone()
d = int(results[3])
print(d*3)

a. P&HEP&HEP&HE
b. 144000
c. WEWEWE
d. 165000
12. 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)

a. {} and fetchone()
b. Fetchone ()and {}
c. %s and fetchone()
d. %eno and fetchone()
13. Consider the following Python code for updating the records:
def Update(eno):
#Assume basic setup import, connection(con) and cursor(mycursor) is
created query="update emp set salary=90000 where empno=” + str(eno)
mycursor.execute(query)

Code is running but the record in actual database is not updating, what could be
the possible reason?
a. save()function is missing
b. con.save()function is missing
c. con.commit()function is missing
d. commit()function is missing
14. Consider the following python code to display all records from table: EMP
def showAll():
#Assume basic setup import, connection(con) and cursor(mycursor) is created
query="select * from emp"
mycursor.execute(query)
results =
mycursor.fetchall()
for results in row:
print(results)
But query is giving error, What could be the possible reason?
a. fetchmany() should be used in place of fetchall()
b. fetchone() should be used in place of fetchone()
c. print(row)should be used in place of print(results)
d. loop and print function is wrong, for row in results : and print(row)should be
used
15.Guess the output:

a. Total records fetched so far are 1


Total records fetched so far are 1
Total records fetched so far are 2
b. Total records fetched so far are 1
Total records fetched so far are 2
Total records fetched so far are 4
c. Total records fetched so far are 1
Total records fetched so far are 2
Total records fetched so far are 2
d. Totalrecordsfetchedsofarare1
Total records fetched so far are 1
Total records fetched so far are1
16. Give one difference between Text file and Binary file.
17.Write a python statement to open a text file “DATA.TXT” so that new contents can be
written on it.
18.What is the purpose of using flush() in file handling operations?
19. Consider a binary file which stores name of employee, where each name occupies 20 bytes
(length of each name) in file irrespective of actual characters. Now you have to write code to
access the first name, 5th name and last name.

f=open("Emp.txt","rb")
s= #code to get first record
print(s.decode())
# code to position at 5th records =
f.read(size)
print(s.decode())
# code to position at last records =
f.read(20)
print(s.decode()) f.close()
20. Write a Python statement to reposition the read pointer to 20 bytes back from the
current position.
f = open("Emp.txt","rb") f.read(20)
f.read(20) f.read(20)
f. # reposition read pointer to previous record f.close()

You might also like