3rd Paper
3rd Paper
25 What do you understand by ORDER BY in SQL? Explain the use of Where clause with 2
SELECT.
OR
What do you mean by degree and cardinality of table?
Section-C
26 a) Table: EMPLOYEES 2+1
Empid Firstname Lastname Address City
010 Ravi Kumar Raj nagar GZB
105 Harry Waltor Gandhi nagar GZB
152 Sam Tones 33 Elm St. Paris
215 Sarah Ackerman 440 U.S. 110 Upton
244 Manila Sengupta 24 Friends street New Delhi
300 Robert Samuel 9 Fifth Cross Washington
335 Ritu Tondon Shastri Nagar GZB
400 Rachel Lee 121 Harrison St. New York
441 Peter Thompson 11 Red Road Paris
Table: EMPSALARY
Empid Salary Benefits Designation
010 75000 15000 Manager
105 65000 15000 Manager
152 80000 25000 Director
215 75000 12500 Manager
400 32000 7500 Salesman
441 28000 7500 salesman
501 18000 6500 Clerk
i) 20#25#25#
ii) 30#40#70#
iii) 15#60#70#
iv) 35#40#60#
b) The code given below inserts the following record in the table
Student: Empno – integer
EName – string
Designation – integer
Salary – integer
Bonus - Integer
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is tiger
The table exists in a MYSQL database named Employee.
The details (Empno, EName, Designation, Salary and Bonus) are to be accepted
from the user.
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
Employee.
Statement 3- to add the record permanently in the database
import mysql.connector as mysql
def sql_data():
con1=mysql.connect(host="localhost",user="root", password="tiger",
database="Employee")
mycursor= #Statement 1
eno=int(input("Enter Employee Number: "))
Ename=input("Enter Employee Name: ")
Designation=input("Enter Designation: "))
Salary=int(input("Enter Salary: "))
Bonus=int(input("Enter Bonus: "))
querry="insert into employee values({},'{}',{},{})".
format(eno,ename,designation,bonus)
#Statement 2
# Statement 3
print("Employee Data Added successfully")
OR
a) Predict the output:
def func(S):
k=len(S)
m=''
for i in range(0,k):
if S[i].isalpha( ):
m=m+S[i].upper( )
elif S[i].isdigit( ):
m=m+'0'
else:
m=m+'#'
print(m)
func("Python 3.9")
b) What are the basic steps to connect Python with MYSQL using table Members
present in the database ‘Society’?
33 Rohit, a student of class 12th, is learning CSV File Module in Python. During examination, 5
he has been assigned an incomplete python code (shown below) to create a CSV File
'Student.csv' (content shown below). Help him in completing the code which creates the
desired CSV File. CSV File
1,AKSHAY,XII,A
2,ABHISHEK,XII,A
3,ARVIND,XII,A
4,RAVI,XII,A
5,ASHISH,XII,A
Incomplete Code
import #Statement-1
fh = open( , , newline='') #Statement-2
stuwriter = csv. #Statement-3
data = []
header = ['ROLL_NO', 'NAME', 'CLASS', 'SECTION']
data.append(header)
for i in range(5):
roll_no = int(input("Enter Roll Number : "))
name = input("Enter Name : ")
Class = input("Enter Class : ")
section = input("Enter Section : ")
rec = [ ] #Statement-4
data.append(rec)
stuwriter. (data) #Statement-5
fh.close()
Answer the following questions
i. Write the suitable code for blank space in line marked as Statement-1
ii. Write the missing code for blank space in line marked as Statement-2?
iii. Write function name (with argument) that should be used in the blank space of line
marked as Statement-3
iv. Complete the statement-4 with suitable code.
v. Write the function name that should be used in the blank space of line marked as
Statement-5 to create the desired CSV File?
OR
Your teacher has given you a method/function FilterWords() in python which read lines
from a text file NewsLetter.TXT, and display those words, which are lesser than 4
characters. Your teachers intentionally kept few blanks in between the code and asked
you to fill the blanks so that the code will run to find desired result. Do the needful with
the following python code.
def FilterWords():
c=0
file=open('NewsLetter.TXT', ' ') #Statement-1
line = file. #Statement-2
word = #Statement-3
for c in word:
if : #Statement-4
print(c)
#Statement-5
FilterWords()
i. Write mode of opening the file in statement-1?
ii. Fill in the blank in statement-2 to read the data from the file.
iii. Fill in the blank in statement-3 to read data word by word.
iv. Fill in the blank in statement-4, which display the word having lesser than 4
v. Fill in the blank in Statement-5 to close the file.
SECTION E
34 A department is considering to maintain their worker data using SQL to store the data. As 4
a Database Administrator, Karan has decided that:
Name of the database –Department
Name of the table –Worker
The attributes of Worker are as follows:
WORKER_ID – CHARACTER OF SIZE 3
FIRST_NAME – CHARACTER OF SIZE 10
LAST_NAME – CHARACTER OF SIZE 10
SALARY – NUMERIC
JOINING_DATE – DATE
WORKER_ID FIRST_NAME LAST_NAME SALARY JOINING_DATE DEPARTMENT
001 MONIKA ARORA 100000 2014-02-20 HR
002 NIHARIKA DIWAN 80000 2014-06-11 Admin
003 VISHAL SINGHAL 300000 2014-02-20 HR
004 AMITABH SINGH 500000 2014-02-20 Admin
005 VIVEK BHATI 500000 2014-06-11 Admin
06 VIPUL DIWAN 200000 2014-06-11 Account
07 SATISH KUMAR 75000 2014-02-20 Account
08 MONIKA CHAUHAN 80000 2014-04-11 Admin
a) Karan wants to remove all the data from table WORKER from the database
department. Write the command to delete above said information.
b) Identify the attribute best suitable to be declared as a primary key.
c) (i) Karan wants to increase the size of the FIRST_NAME column from 10 to
20 characters. Write an appropriate query to change the size.
(ii) Write a query to display the structure of the table Worker, i.e. name of the
attribute and their respective data types
OR (only for part c)
Write command to create above table
35 Amritya Seth is a programmer, who has recently been given a task to write a python code 4
to perform the following binary file operations with the help of two user defined
functions/modules:
a. AddStudents() to create a binary file called STUDENT.DAT containing student
information – roll number, name and marks (out of 100) of each student.
b. GetStudents() to display the name and percentage of those students who have a
percentage greater than 75. In case there is no student having percentage > 75 the
function displays an appropriate message. The function should also display the average
percent.