0% found this document useful (0 votes)
3 views

Practical file(Ashish) - Copy

The document is a project file submitted by Ashish Rawat of Kendriya Vidyalaya Jharoda Kalan, focusing on various programming tasks related to company management. It includes multiple Python programs for tasks such as counting vowels and words in a text file, manipulating file contents, and database operations using MySQL. The project is supervised by Mrs. Priyanka and acknowledges support from the principal and classmates.

Uploaded by

kshitijgusain69
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Practical file(Ashish) - Copy

The document is a project file submitted by Ashish Rawat of Kendriya Vidyalaya Jharoda Kalan, focusing on various programming tasks related to company management. It includes multiple Python programs for tasks such as counting vowels and words in a text file, manipulating file contents, and database operations using MySQL. The project is supervised by Mrs. Priyanka and acknowledges support from the principal and classmates.

Uploaded by

kshitijgusain69
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 31

KENDRIYA VIDYALAYA

JHARODA KALAN
NEW DELHI-110072

A PROGRAM FILE

SUBMITTED TO SUBMITTED
BY:
MRS. PRIYANKA ASHISH RAWAT

P.G.T.(COMP. SC)

CERTIFICATE
This is to certify that Ashish of class XII A of
Kendriya Vidyalaya Jharoda Kalan has done
his project on Company Management under my
supervision. He has taken interest and has shown
at most sincerity in completion of this project.

I certify this Project up to my expectation & as


per guidelines issued by CBSE, NEW DELHI.

Internal Examiner

ACKNOWLEDGMENT

It is with pleasure that I acknowledge my sincere


gratitude to our teacher, Mrs. Priyanka who
taught and undertook the responsibility of
teaching the subject computer science. I have
been greatly benefited from her classes.
I am especially indebted to our Principal Mr. Sunil
Kumar who has always been a source of
encouragement and support and without whose
inspiration this project would not have been a
successful I would like to place on record
heartfelt thanks to him.
Finally, I would like to express my sincere
appreciation for all the other students for my
batch their friendship & the fine times that we all
shared together.
1)Write a program to count the no
of vowels in a text file?
Ans) text file is-
def vowel_count(str):
count = 0
vowel = set("aeiouAEIOU")
for alphabet in str:
if alphabet in vowel:
count = count + 1
print("No. of vowels :", count)
str = "Ashish"
vowel_count(str)

output
# No. of vowels : 2

2)write a program to count no of


words in a text file?
Ans) text file is---

infile=open(“file.txt”,”r”)
data=infile.read()
numofwords=len(data.split())
print(numofwords

output-
# 13

3)Write a program to write those


line having character “p” from
one text file to another text file?
Ans) text file is-

def Displayp():
f=open("file.txt")
while True:
line=f.readline()
if line==(" "):
break
if "p" in line:
print(line)
f.close()
Displayp()
Output-
#

4)write a program to read a text file line


by line display each word separated by a
#?
Ans) text file is-

file=open("file.txt","r")
content=file.readlines()
for line in content:
words=line.split()
for word in words:
print(word+"#",end=" ")
print("")

output-
#

5)Write a program to read a text file and


display the no of vowels/consonant/upper
case and lower case characters?
Ans) text file is-

output—
#

file=open("file.txt","r")
data=file.read()
vowels=0
consonent=0
uppercase=0
lowercase=0
for ch in data:
if str.isupper(ch):
uppercase+=1
elif str.islower(ch):
lowercase+=1
ch=str.lower(ch)
if ch in "aeiou":
vowels+=1
elif ch in "bcdfghjklmnpqrstvwxyz":
consonent+=1
print("No of vowels:",vowels)
print("No of consonents:",consonent)
print("No of uppercase letter:",uppercase)
print("No of lowercase letter:",lowercase)

6)write a program to create a binary file


with name and roll no .search for a given
roll no and display the name if not found
display appropriate message?
Ans)
import pickle
file=open("file.txt","wb")
dic={}
for key in range(5):
rollno=int(input("enter roll no"))
name=input("enter name")
dic[rollno]=name
pickle.dump(dic,file)
file.close()

out put—
#

7)write a program to remove all the lines


contain letter ”a” in a file ?
Ans)
file=open("file.txt","r")
lines=file.readlines()
file.close()
file=open("file.txt","w")
file1=open("files.txt","w")
for line in lines:
if "a" in line:
file1.write(line)
else:
file.write(line)
print("file")
print("files")
file.close()
file1.close()
out put—
file
8)write a program to create a csv files and
store emp no and display name,salary and
if not found appropriate message should
be displayed?
Ans)
import csv
file=open("student.csv","a")
A=[]
w=csv.writer(file)
w.writerow(["roll no","name","marks"])
n=1
while n<2:
r=int(input("enter roll no of student:"))
name=input("enter student name:")
marks=float(input("enter marks of student:"))
A.append([r,name,marks])
n=n+1
w.writerows(A)
file.close()
print("records added sucessfully")

output—

10)Write a random no generator that


generates random no between 1 and 6?
Ans)
import random

def rolladice():

counter=0

Mylist=[]

while(counter)>=6:

randomNumber=random.randint(1,6)

Mylist.append(randomNumber)

counter=counter+1

if(counter)>=6:

pass

else:

return Mylist

n=1

while(n==1):

n=float(input("enter 1 to roll a dice and get a random number:"))

print(rolladice())

output---
#

11)write a program to sort a list using


insertion sort technique?
Ans)
def InsertionSort(my_list):

for index in range(1,len(my_list)):

current_element=my_list[index]

pos=index

while current_element<my_list[pos-1] and pos>0:

my_list[pos]=my_list[pos-1]
pos=pos-1

my_list[pos]=current_element

list1=[1,3,2,5,7,4]

InsertionSort(list1)

print(list1)

output—

12)write a program to sort a list using


bubble sort technique?
Ans)
list1=[1,5,3,8,5]

print("unsorted list:",list1)

for j in range(len(list1)-1):

for i in range(len(list1)-1-j):

if list1[i]>list1[i+1]:

list1[i],list1[i+1]=list1[i+1],list1[i]

print(list1)
else:

print(list1)

print()

print("sorted list:",list1)

13)Write a python program to implement


a stack using a list data structure?
Ans)
stack=["Ashish","PhoenixFF","FF"]

stack.append("Drag")

stack.append("Headshot")

print(stack)

print(stack.pop())

print(stack)

print(stack.pop())

print(stack)

output—
#

Ans 14:-
alst=eval(input(‘enter list:’))
for i in range(1,len(alst)):
a=alst[i]
k=0
for j in range(i-1,-2,-1):
k=j
if alst[j]>a[j]:
alst[j+1]=alst[j]
else:
alst[j+1]=a
break
alst[k+1]=a
print(‘sorted list:’,alst)

Ans 15:-
stack=["asdfg","PhoenixFF","FF"]
stack.append("Drag")
stack.append("Headshot")
print(stack)
print(stack.pop())
print(stack)
print(stack.pop())
print(stack)

Ans16:-
import collections
fin = open('D:\\email.txt','r')
a= fin.read()
d={ }
L=a.lower().split()
for word in L:
word = word.replace(".","")
word = word.replace(",","")
word = word.replace(":","")
word = word.replace("\"","")
word = word.replace("!","")
word = word.replace("&","")
word = word.replace("*","")
for k in L:
key=k
if key not in d:
count=L.count(key)
d[key]=count

n_print = int(input("How many most common words to print: "))


print("\nOK. The {} most common words are as follows\
n".format(n_print))
word_counter = collections.Counter(d)
for word, count in word_counter.most_common(n_print):
print(word, ": ", count)
fin.close()

Ans 17:-
import mysql.connector as mys
conn=mys.connect(host=’localhost’,user=’root’,passwd=’tiger’,
database=’company’)
c=conn.cursor()
a.execute(‘select * from employee’)
a.fetchall()

Ans 18:-
import mysql.connector as mys
conn=mys.connect(host=’localhost’,user=’root’, passwd=’tiger’,
database=’company’)
cur=conn.cursor()
n=input(‘enter employee name:’)
try:
cur.execute(‘select * from employee where name=(%s)’,n)
except:
print(‘entered employee name is not exists in database’)

Ans 19:-
import mysql.connector as mys
conn=mys.connect(host=’localhost’,user=’root’, passwd=’tiger’,
database=’company’)
cur=conn.cursor()
a=’y’
while a==’y’:
empno=input(‘enter empno value:’)
name=input(‘enter employee name’)
phno=int(input(‘enter employee ph no.:’))
add=input(‘enter employee address:’)
cur.execute(‘update employee set name=%s,phno.=%s,add=%

where empno=%s’,(name,phno,add,empno))

a=input(‘want to change value again(y/n):’)

Ans 20:-
import mysql.connector as mys
conn=mys.connect(host=’localhost’,user=’root’, passwd=’tiger’,
database=’company’)
cur=conn.cursor()
a=’y’
while a==’y’:
empno=input(‘enter empno value:’)

cur.execute(‘delete*from employee where empno=%s’,empno)

a=input(‘want to delete more recordes:’)

MYSQL:-
Ans 1:-
-use company;
-create table Employee(No char(2),Name varchar(20),Zone
varchar(20),Age char(3),Grade varchar(2),Dept char(3));

-insert into employee values(1,Mukul,30000,West,28,A,10)

(2,Kritika,35000,Center,30,A,10),(3,Naveen,32000,West,40,NULL,20),
(4,Uday,38000,North,38,C,30),(5,Nupur,32000,East,26,Null,20),
(6,Moksh,37000,South,28,B,10),(7,Shelly,36000,North,26,A,30);

-ceate table Department(Dept char(3),DName varchar(20),MinSal


char(7), MaxSal char(7),HOD char(2));

-insert into department values(10,Sales,25000,32000,1),(20,Finance ,


30000,50000,5),(30,Admin,25000,40000,7);

Ans 2:-
-Select * from employee;

Ans 3:-
-Select salary, grade , zone from employee;

Ans 4:-
-Select no,name,salary,annualsalary from employee where
annualsalary=salary*12;

Ans 5:-
-select no,name,salary,dept,age,annualsalary from employee where
annualsalary=salary*12;
Ans 6:-
-select * from employee where age<30;

Ans 7:-
-Select * from employee where zone=north;

Ans 8:-
-select salary from employee where dept=10;
Ans 9:-
-select * from employee where grade is null;
Ans 10:-
-select * from employee where grade is not null;
Ans 11:-
-select distinct(zone) from employee;
Ans 12:-
-select distinct(dept) from employee;
Ans 13:-
-select * from employee where dept=10 and age>30;
Ans 14:-
-select * from employee where dept=30 and salary>35000;
Ans 15:-
-select name,salary from employee where zone!= west and zone!
=center;

Ans 16:-
-select name from employee where dept=20 or 30;
Ans 17:-
-select * from employee where salary between (32000,35000);
Ans 18:-
-select * from employee where grade !=A and grade !=C;

Ans 19:-
-select name from employee where dept =20 or 30;

Ans 20:-
-select name , salary from employee where zone!=west and zone !=
center;

Ans 21:-
-select * from employee where salary<38000 and salary>32000;

Ans 22:-
-select * from employee where grade between(A,C);

Ans 23:-
-select name,salary,age from employee where name=M%;

Ans 24:-
-select name,salary,age from employee where name=%a;

Ans 25:-
-select name,salary,age from employee where name=a% or %a or %a
%;

Ans 26:-
-select name,salary,age from employee where name!=a% or %a or
%a%;

Ans 27:-
-select * from employee where name=_a%;

Ans 28:-
-Select sum(salary),avg(salary) from employee;

Ans 29:-
-select max(salary),min(salary) from employee where dept=10;

Ans 30:-
-select count(name) from employee where dept=10;

Ans 31:-
-Select * from employee order by salary;

Ans 32:-
-Select * from employee order by name desc;

Ans33:-
-select * from employee order by grades;

Ans 34:-
-select dept ,count(*) from employee group by dept;
Ans 35:-
-select max(salary) ,min(salary) ,avg(salary) from employee group by
distinct(dept);

Ans 36:-
-select avg(age) from employee where age>30;
Ans 37:-
-update employee set grades=B where grade is null;
Ans 38:-
-update employee set salary=salary+salary*0.1 where age>=30;
Ans 39:-
-delete from employee where grades=C and salary<30000;
Ans 40:-
-delete from employee where dept=10 and age>40;
Ans 41:-
-alter table employee add HireDate varchar(20);
Ans 42:-
-select * from employee E ,department D where D.dept=E.dept and
dname=sales;

Ans 43:-
-select name ,dname from employee E ,department D where
E.dept=D.dept;

Ans 44:-
-drop table employee;
Ans 45:-
-drop table department;

You might also like