You are on page 1of 34

KENDRIYA VIDYALAYA AFS, SEC-14

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--

2- To find the occurrence of word H and h together in the text file.


F = open("CsTheory.txt")
S = F.read()
Count = 0
for i in S:
if i == 'h' or i == 'H':
Count+=1
print("The Occurence of H and h together in the file is ",Count)
F.close()
--Output--

3- To read a Text file and check the Number of occurrence of letter A.


F = open("Story.txt")
K = F.read()
Count = 0
for i in K:
if i.lower() == "a":
Count+=1
print("The occurrence of a in the file is ",Count)
F.close()
--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--

5- To count uppercase characters and digits present in the file.


F = open("Doc1.txt")
k = F.read()
D=0
U=0
for i in k:
if i.isdigit():
D+=1
if i.isupper():
U+=1
print("The total number of digits in the file are..",D)
print("The total number of Uppercase chaaracter in the file are..",U)
F.close()
--Output--
6- To Count and Display Uppercase,Lowercase,Vowel and
Consonants from the file.
F = open("Doc1.txt")
k = F.read()
V=0
U=0
L=0
D=0
A = ['a','e','i','o','u']
for i in k:
if i.isdigit():
D+=1
if i.islower():
L+=1
if i.isupper():
U+=1
if i.lower() in A:
V+=1
Length = len(k)
C = Length-(D+V)
print("The Number of consonants in the file is..",C)
print("The Number of digits in the file is..",D)
print("The Number of vowels in the file is..",V)
print("The Number of uppercase character in the file is..",U)
print("The Number of lowercase character in the file is..",L)
F.close()
--Output--

7- To print a pyramid using “#”


n=4
for i in range(n):
for j in range(n-i):
print("*",end=" ")
for i in range(i+1):
print(" ",end="")
print()
--Output--

8- Function to find area of rectangle.


def Rectanglearea():
l = float(input("Enter the length of rectangle"))
b = float(input("Enter the breadth of recatngle"))
A = l*b
print("Area of given rectangele is",A)

--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--

10- Using function to get a number N and check whetever number is


prime number or not and return 0 if number is prime else return 1.
def Prime():
N = float(input("Enter the number"))
if N%2 == 0:
return 1
else:
return 0
--Output--

11- Function to check a number is palindrome or not.


def palindrome():
N = list(input("enter your number"))
K = N[::-1]
if N == K:
print("The given number is a palindrome")
else:
print("The given number is not palindrome")
--Output--

12- Function to calculate Compound Interest


def CompoundInterest():
p = float(input("Enter the pricipal "))
r = float(input("Enter the rate"))
t = float(input("Enter the time"))
amount = p*(1+r/100)**t
Ci = amount - p
print("The Compund Interest calculated = ",Ci)
--Output--

13- Function to stimulate a dice.


import random
def Dice():
a = random.randint(1,6)
print(“The Random Number is”,a)
--Output--

14- Function to find sum of elements of list.


def Sum():
l = []
k = int(input("enter the how many entires you want to be in list"))
while k>0:
a = int(input("enter the number you want to be in list"))
l.append(a)
k-=1
b = sum(l)
print("The sum of elements in list",b)
--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--

20- Program to write the content in a binary file


import pickle
stu=[]
fin=open('student.dat', 'wb')
finl=open('studentl.dat', 'wb')
ans='y'
while ans=='y':
admin_no=int(input ("Enter admission number: :"))
name=input ("Enter name ::")
fee=float (input ("Enter fee::"))
stu.append([admin_no, name, fee])
ans=input ("Want to enter more records::")
pickle.dump (stu, fin)
fin.close()

--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--

23- Program to display the information 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)
print ("%10s"%"Admission No","%20s"%"Student Name", "%20s"%"Fee")
print ("-------------------------------------------------------")
for i in stu:
print("%10s"%i[0],"%20s"%i[1],"%20s"%i[2])
fout.close()

--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--

25- Program to update a binary file.


import pickle
import os
stu=[]
fin=open('student.dat', 'rb+')
stu= pickle.load(fin)
l=len (stu)
found=False
n=int(input ("Enter admission number to search:::"))
for i in range(l) :
if (stu[i][0]==n):
print ('Record Found :')
print('Name :',stu[i][1])
print('Fee :',stu[1] [2])
print ("-"*40)
print ("What information you want to update")
print ("Enter 1 for admission number: :")
print ("Enter 2 for Name: :")
print ("Enter 3 for fee: :")
ch=int (input("Enter your choice::"))
print ("-"*40)
found=True
if ch==1:
newadno=int (input("Enter new admission number: :"))
stu[1][0]=newadno
elif ch==2:
newname=input ("Enter name: :")
stu[i][1]=newname
elif ch==3:
newfee=float (input("Enter fee"))
stu[i][2]=newfee
print ("The data is updated:::")
break
fin.seek(0)
pickle.dump (stu, fin)
if found:
print("After updation Data is :")
print('Name :',stu[i][1])
print('Fee :',stu[1] [2])

--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

FNO AIRLINES FARE TAX_PERCENTAGE


IC301 Indian Airlines 9425 5
IC799 Spice Jet 8846 10
MC101 Deccan Airlines 4210 7
IC302 Jet Airways 13894 5
AM812 Indian Airlines 4500 6
MU499 Sahara 12000 4

CREATE TABLE FLIGHTS


-> (
-> FNO VARCHAR(5),
-> SOURCE VARCHAR(50),
-> DESTINATION VARCHAR(50),
-> NO_OF_FLIGHTS INT(5),
-> NO_OF_STOP INT(5)
-> );

--Output—

CREATE TABLE FARES


-> (
-> FNO VARCHAR(5),
-> AIRLINES VARCHAR(50),
-> FARAE INT(5),
-> TAX_PERCENTAGE INT(5)
-> );

--Output—

i- Display flight number & number of flights from Mumbai


from the table flights.
SELECT FNO,NO_OF_FLIGHTS FROM FLIGHTS
-> WHERE SOURCE='MUMBAI';

--Output—

ii- Arrange the contents of the table flights in the descending


order of destination.
SELECT * FROM FLIGHTS
-> ORDER BY DESTINATION DESC;

--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--

1- Write a command to create the below given table:

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

INSERT INTO DEPARTMENT


VALUES(10,'FIANANCE','GGN');
INSERT INTO DEPARTMENT
VALUES(20,'PROGRAMMING','GGN');
INSERT INTO DEPARTMENT
VALUES(30,'HRM','DELHI');

--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--

i- Write a query to display the data of department table.


SELECT * FROM DEPARTMENT;

--Output--

ii- Write a query to display the data of employee table.


SELECT * FROM EMPLOYEE;

--Output--

iii- Write query to display name, gender and salary of all


employee in ascending order of their salary.
SELECT NAME,GENDER,SALARY FROM EMPLOYEE
-> ORDER BY SALARY;

--Output--
iv- Write a query to display the list of departments which are
located in GGN.
SELECT DNAME FROM DEPARTMENT
-> WHERE DLOC='GGN';

--Output--

v- Write a query to display name of all the employee who are


living in Gurgaon .
SELECT NAME FROM EMPLOYEE
-> WHERE CITY='GGN';

--Output--

vi- Write a query to display the details of employee whose


empno is 105.
SELECT * FROM EMPLOYEE
-> WHERE EMPNO=105;
--Output--

vii- Write a query to display all male employees living in delhi


SELECT NAME FROM EMPLOYEE
-> WHERE CITY='DELHI' AND GENDER='M';

--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--

xiv- Write a query to change the city to Rohtak of employee


whose employee no is 104.
UPDATE EMPLOYEE
-> SET CITY='ROHTAK'
-> WHERE EMPNO=104;

--Output--

xv- Write a query to delete the records of all the employees of


department no 10 .
DELETE FROM EMPLOYEE
-> WHERE DNO=10;

--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()

You might also like