Professional Documents
Culture Documents
GURUGRAM
PRACTICAL FILE
AISSCE-2023-24
SUBMITTED TO SUBMITTEDBY:
MRS.NISHA PARIMAR SIYA SINGH
P.G.T.(COMP. SC)
1- Function for a Calculator.
def Add():
a = int(input("Enter the First Number"))
b = int(input("Enter the Second Number"))
c = a+b
print(c)
def Subtract():
a = int(input("Enter the First Number"))
b = int(input("Enter the Second Number"))
c = a-b
print(c)
def Multiply():
a = int(input("Enter the First Number"))
b = int(input("Enter the Second Number"))
c = a*b
print(c)
def Divide():
a = int(input("Enter the First Number"))
b = int(input("Enter the Second Number"))
c = a/b
print(c)
while (True):
print("Kindly choose the operation on the Numbers")
print("-1:For Addition")
print("-2:For Subtraction")
print("-3:For Multiplication")
print("-4:For Divison")
print("--Choose any another to exit calculator")
i=int(input(">"))
if i == 1:
Add()
elif i == 2:
Subtract()
elif i == 3:
Multiply()
elif i == 4:
Divide()
else:
break
--Output--
4- To read the content and display the content of file such that the
letter E is printed instead of I.
F = open("Story.txt")
K = F.read()
for i in K:
if i == "E":
print("I",end="")
else:
print(i,end="")
F.close()
--Output--
--Output--
9- Using function to get a number N and check whetever number is
odd or even and return 0 if number is even else return 1.
def EvenOdd():
N = float(input("Enter the number"))
if N%2 == 0:
return 0
else:
return 1
--Output--
15- Program to read a file and display all the lines starting with T.
F = open("Story.txt","r")
k = F.readlines()
for i in k:
if i[0][0]=="T":
print(i,end = "")
F.close()
--Output--
16- Program to remove all the line containg character a and write it
to a another file.
F = open("Story.txt","r")
k = F.readlines()
f = open("Story.txt","w")
s = open("Cs.txt","w")
t= []
for i in k:
if "a" in i:
s.write(i)
else:
t.append(i)
f.writelines(t)
print("Process Succesfully Complete")
s.close()
F.close()
f.close()
--Output--
17- Creating a Csv file with name and roll number and searching for
a given roll number and display the name,if not found displaying a
appropriate message.
import csv
File=open("Student.csv","w",newline="")
WriteObj=csv.writer(File)
WriteObj.writerow(["Name","Roll No"])
File.close()
File=open("Student.csv","r")
R=input("Enter the Roll number ")
ReaderObj=csv.reader(File)
Name='Null'
for r in ReaderObj:
if R in r:
Name=r[1]
print('Name of the Student is-',Name)
if Name=='Null':
print("Sorry! The Roll Number Doesn't exist in the Records")
File.close()
18- Creating Csv file with Empno,Name and Salary and Displaying
all records having salary more than 10000.
import csv
File=open("Employee.csv","w",newline="")
WriteObj=csv.writer(File)
WriteObj.writerow(["Empno","Name","Salary"])
File.close()
File=open("Employee.csv","r")
ReaderObj=csv.reader(File)
for r in ReaderObj:
if int(r[2])>100000:
print("Record of employee is",r)
File.close()
19- Program to read and write the content from a binary file
import pickle
n = int(input ("enter a n value:"))
d = {}
for i in range (n) :
keys = int(input ("Enter roll no."))
values = input ("Enter name of the student")
d[keys]= values
fin=open ("employee.dat", "wb")
pickle.dump (d, fin)
fin.close()
fout=open("employee.dat", "rb")
d=pickle.load(fout)
for k, v in d.items():
print (k,':',v)
fout.close()
--Output--
--Output--
21- Program to read the total number of records from a binary file.
import pickle
import os
stu=[]
fout=open("Student.dat","rb")
if os.path.isfile("Student.dat")==True:
stu=pickle.load(fout)
l=len(stu)
print("Total number of records::",l)
fout.close()
--OUTPUT--
22- Program to read the content from a binary file.
import pickle
import os
stu=[]
fin=open("employee.dat","rb")
stu=pickle.load(fin)
fin.seek(0,0)
print(stu)
--Output--
--Ouput--
24- Program to search a record from a binary file
import pickle
import os
stu=[]
fout=open('student.dat', 'rb')
ans='y'
adno=int (input ("Enter admission number to search:::"))
found=False
if os.path.isfile ('student.dat')==True:
stu=pickle.load(fout)
print ("%10s"%"Admission No", "%20s"%"Student Name", "%20s"%"Fee")
print ("--------------------------------------------------------")
for i in stu:
if (i[0]==adno):
print("%10s"%i[0],"%20s"%i[1], "%20s"%i[2])
found=True
break
if found==False:
print ("The required data is not present in the file::")
fout.close()
--Output--
--Output—
26- Create the following table FLIGHTS & FARES by considering the
datatype of each column by your own.
Table : FLIGHTS
FNO SOURCE DESTINATION NO_OF_FLIGHTS NO_OF_STOP
IC301 MUMBAI BANGALORE 3 2
IC799 BANGALORE KOLKATA 8 3
MC101 DELHI VARANASI 6 0
IC302 MUMBAI KOCHI 1 4
AM812 LUCKNOW DELHI 4 0
MU499 DELHI CHENNAI 3 3
Table : FARES
--Output—
--Output—
--Output—
--Output--
iii- Increase the tax by 2% for the flights starting from Delhi.
UPDATE FLIGHTS A,FARES B
SET TAX_PERCENTAGE=TAX_PERCENTAGE+2
WHERE A.FNO=B.FNO AND SOURCE=’DELHI’;
--Output—
iv- Display the flight number and fare to be paid for the flights
from Mumbai to Kochi using the tables, Flights & Fares,
where the fare to be paid =fare+fare*tax/100.
SELECT FNO,FARE FROM FARES A NATURAL JOIN FLIGHTS B
-> WHERE SOURCE='MUMBAI' AND DESTINATION='KOCHI'AND
FARE=FARE+FARE*TAX_PERCENTAGE/10000;
--Output--
v- Display total no of source stations(eliminate duplicate)
present in the table.
SELECT DISTINCT SOURCE FROM FLIGHTS;
--Output--
vi- Display the fare for the flight for MUMBAI to BANGLORE.
SELECT FARE FROM FLIGHTS A,FARES B
-> WHERE A.FNO=B.FNO AND SOURCE='MUMBAI' AND
DESTINATION='BANGALORE';
--Output--
vii- Display the records of source stations started with letter ‘B’.
SELECT * FROM FLIGHTS
-> WHERE SOURCE LIKE 'B%';
--Output--
viii- Display the flight no. for which fare to be paid is less than
3000.
SELECT FNO FROM FARES
-> WHERE FARE<3000;
--Ouput--
ix- Display total no. of flights available for each Airlines.
SELECT SUM(NO_OF_FLIGHTS) FROM FLIGHTS A,FARES B
-> WHERE A.FNO=B.FNO
-> GROUP BY AIRLINES;
--Output--
x- Add a new column Dep_Time in the table Flight.
ALTER TABLE FLIGHTS
-> ADD DEP_TIME TIME;
--Output—
xi- Delete the record of flight no. IC301 from the table FARE.
DELETE FROM FARES
-> WHERE FNO='IC301';
--Output--
xii- Increase the size of the column ‘source’ to 30 in the Table
FLIGHT.
ALTER TABLE FLIGHTS
-> MODIFY SOURCE VARCHAR(30);
--Output--
Table: Department
Table: Employee
CREATE TABLE DEPARTMENT
(
DNO INTEGER PRIMARY KEY,
DNAME VARCHAR(30) NOT NULL,
DLOC CHAR(50));
--Output--
CREATE TABLE EMPLOYEE
(
EMPNO INTEGER PRIMARY KEY,
NAME VARCHAR(50) NOT NULL,
GENDER CHAR(1) CHECK(GENDER IN ('M','F')),
CITY VARCHAR(30) DEFAULT 'GGN',
SALARY DECIMAL(5,2) CHECK(SALARY>10000),
DNO INTEGER REFERENCES DEPARTMENT(DNO));
--Output--
Inserting the following data in the table:
Table: Department
Table:Employee
--Qutput--
INSERT INTO EMPLOYEE
VALUES(101,'NAINA','F','DELHI',70000.00,10);
INSERT INTO EMPLOYEE
VALUES(102,'SOHAN','M','GGN',50000.00,20);
INSERT INTO EMPLOYEE
VALUES(103,'MOHAN','M','GGN',25000.00,30);
INSERT INTO EMPLOYEE
VALUES(104,'REENA','F','DELHI',30000.00,10);
INSERT INTO EMPLOYEE
VALUES(105,'TEENA','F','GGN',35000.00,10);
--Output--
--Output--
--Output--
--Output--
iv- Write a query to display the list of departments which are
located in GGN.
SELECT DNAME FROM DEPARTMENT
-> WHERE DLOC='GGN';
--Output--
--Output--
--Output--
viii- Write a query to display the details of employees of
department no 10 in descending order of their names.
SELECT * FROM EMPLOYEE
-> WHERE DNO=10
-> ORDER BY NAME DESC;
--Output--
ix- Write a query to display name and salary of all the employee
whose salary lies between 30 thousand to 50 thousand.
SELECT NAME,SALARY FROM EMPLOYEE
-> WHERE SALARY BETWEEN 30000 AND 50000;
--Output--
x- Write a query to display the records of all the employee
who are either female or working in department no 30
SELECT * FROM EMPLOYEE
-> WHERE GENDER='F' OR DNO=30;
--Output--
xi- Write a query to display the detail of all the employee, the
last second character of whose name is a.
SELECT * FROM EMPLOYEE
-> WHERE NAME LIKE '%a_';
--Output--
xii- Write a query to delete all the records who are living in
Gurgaon.
DELETE FROM EMPLOYEE
-> WHERE CITY='GGN';
--Output-
xiii- Write a query to increase the salary of all the employees by
15% of their existing salary.
UPDATE EMPLOYEE
-> SET SALARY=SALARY+SALARY*15/100;
--Output--
--Output--
--Output--
xvi- Write a query to add one more column i.e dob date not null.
ALTER TABLE EMPLOYEE
-> ADD DOB DATE NOT NULL;
--Output--
27- Python program which will get the data of table created in
question no 61 above and display the data on output screen(by
using connectivity of python and mysql)
import pymysql as mc
con=mc.connect(host='localhost',user='root',password=' ',db='MKP')
cr=con.cursor()
cr.execute("SELECT * FROM DEPARTMENT;")
data=cr.fetchall()
print('-'*40)
print('%10s'%'DNO','%15s'%'DNAME','%10s'%'DLOC')
print('-'*40)
for i in data:
print('%10s'%i[0],'%15s'%i[1],'%10s'%i[2])
print('-'*80)
cr.execute("SELECT * FROM EMPLOYEE;")
data1=cr.fetchall()
print('%10s'%'EMPNO','%15s'%'NAME','%10s'%'GENDER','%10s'%'CITY','%10s'
%'SALARY','%10s'%'DNO')
print('-'*80)
for i in data1:
print('%10s'%i[0],'%15s'%i[1],'%10s'%i[2],'%10s'%i[3],'%10s'%i[4],'%10s'%i[5])
--Output--
28- Python program which will get the data of table created in
question no 61 above and display the data on output screen
whose city is delhi(by using connectivity of python and mysql).
import pymysql as mc
con=mc.connect(host='localhost',user='root',password=' ',db='MKP')
cr=con.cursor()
cr.execute("SELECT * FROM EMPLOYEE;")
data=cr.fetchall()
print('-'*80)
print('%10s'%'EMPNO','%15s'%'NAME','%10s'%'GENDER','%10s'%'CITY','%10s'
%'SALARY','%10s'%'DNO')
print('-'*80)
for i in data:
if i[3]=='DELHI':
print('%10s'%i[0],'%15s'%i[1],'%10s'%i[2],'%10s'%i[3],'%10s'%i[4],'%10s'%i[5])
--Output--
29- Python program which will get the data of table created in
question no 61 above and display the data of all female
employees on output screen(by using connectivity of python and
mysql).
import pymysql as mc
con=mc.connect(host='localhost',user='root',password=' ',db='MKP')
cr=con.cursor()
cr.execute("SELECT * FROM EMPLOYEE;")
data=cr.fetchall()
print('-'*80)
print('%10s'%'EMPNO','%15s'%'NAME','%10s'%'GENDER','%10s'%'CITY','%10s'
%'SALARY','%10s'%'DNO')
print('-'*80)
for i in data:
if i[2]=='F':
print('%10s'%i[0],'%15s'%i[1],'%10s'%i[2],'%10s'%i[3],'%10s'%i[4],'%10s'%i[5])
--Output--
30- Python program which will consider the table given in question
no 61 above and give increment of 5000 to all employee by using
update command(by using connectivity of python and mysql).
import pymysql as mc
con=mc.connect(host='localhost',user='root',password=' ',db='MKP')
cr=con.cursor()
cr.execute("UPDATE EMPLOYEE SET SALARY=SALARY+50000;")
con.commit()