0% found this document useful (0 votes)
33 views31 pages

Amit Practical

Uploaded by

srishti8851
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)
33 views31 pages

Amit Practical

Uploaded by

srishti8851
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/ 31

ARYA VIDYA MANDIR SR. SEC.

SCHOOL

ACADEMIC YEAR: 2024-25

PROJECT FILE

SUBMITTED BY: SUBMITTED TO:

NAME : Amit Mrs. Monika Goyal


ROLL NO. : ____________ PGT(Computer)
CLASS/SEC : XII - D
SUBJECT : COMPUTER SCIENCE(083)
PROGRAM 1
AIM: WAP to create a calculator?
Code:
s=0
def add():
a=int(input("enter a no."))
b=int(input("enter a no."))
s=a+b
print(s)
def subtract():
a=int(input("enter a no."))
b=int(input("enter a no."))
s=a-b
print(s)
def multiply():
a=int(input("enter a no."))
b=int(input("enter a no."))
s=a*b
print(s)
def divide():
a=int(input("enter a no."))
b=int(input("enter a no."))
s=a/b
print(s)
def square():
n=int(input("enter a no. whose square you want"))
print(n**2)
print("what do u want 1 add 2 subtract 3 multiply 4 divide 5 square ")
c=int(input("what do u want"))
if c==1:
add()
elif c==2:
subtract()
elif c==3:
multiply()
elif c==4:
divide()
else:
square()
print("amit")
output
PROGRAM 2
AIM: WAP to search operation in file?
Code:
import pickle
f=open("rat.dat","rb")
try:
while True:
s=pickle.load(f)
if s["salary"]>20000:
print(s["name"])
except:
f.close()
print (“amit”)
PROGRAM 3
AIM: WAP to update a file.
Code:
import pickle
def update():
f=open("emp.dat","rb+")
try:
while True:
pos=f.tell()
s=pickle.load(f)
if s["name"]=="mohit":
s["name"]="mohit ji"
f.seek(pos)
pickle.dump(s,f)
except:
f.close()
PROGRAM 4
AIM: WAP to start with a vowels.
Code:
f=open("aample.txt","r")
s=f.readlines()
for i in s:
if i[0] not in "aeiouAEIOU":
print(i)
print("amit")

PROGRAM 5
AIM: WAP to operate a text file?
Code:
f=open("sample.txt","w")
s="hlo python"
f.write(s)
f.close()
print("amit")

PROGRAM 6
AIM: calculate size of file?
Code:
f=open("sample.txt","r")
s=f.read()
l=len(s)
print("total no. of bytes/size",l)
print("amit")

PROGRAM 7
AIM: WAP to display total no. of words in a file?
Code:
f=open("sample.txt","r")
s=f.read()
l=s.split()
n=len(l)
print(n)
print("amit")

PROGRAM 8
AIM: WAP to display a total no. of line in a file?
Code:
f=open("sample.txt","r")
s=f.readlines()
l=len(s)
print("total no. of lines in a file",l)
print("amit")

PROGRAM 9
AIM: WAP to create operation on binary file?
Code:
import pickle
f=open("emp.dat","wb")
d={"name":"amitji","empno.":432,"salary":39000}
d1={"name":"amrit ji","emp.":423,"salary":36000}
pickle.dump(d,f)
pickle.dump(d1,f)
f.close()
print(“amit”)
PROGRAM 10
AIM: WAP to display a reading on binary file?
Code:
import pickle
f=open("emp.dat","rb")
s=" "
try:
while True:
s=pickle.load(f)
print(s)
except:
print(";no more data to display")
f.close()
print(“amit)
PROGRAM 11
AIM: WAP to operate on csv file?
Code:
import csv
f=open("record.csv","w")
a="y"
p=csv.writer(f)
while a=="y":
name=input("entert name")
rn=int(input("enter rollno."))
marks=int(input("enter ur marks"))
l=[name,rn,marks]
p.writerow(l)
a=input("do u want to enter new record.pressy")
f.close()
PROGRAM 12
AIM: WAP to read a binary file ?
Code:
import csv
f=open("record.csv","r")
r=csv.reader(f)
for i in r:
print(r)
prin(“amit”)
PROGRAM 13
AIM: WAP to implement different types of argument?
Code:
(i) positional
def check(x,y):
if x>10:
print("x is big")
elif y>10:
print("y is big")
check(2,23)
print(“amit”)
output:-
(ii) keyword:-
def check(x,y):
if x>10:
print("x is big")
elif y>10:
print("y is big")
check(y=2,x=23)
print(“amit”)
Output:-
(iii) default:-
def check(x,y=2):
if x>10:
print("x is big")
elif y>10:
print("y is big")
check(18)
print(“amit”)

Output:-
PROGRAM 14
AIM: WAP to implement stack operation?
Code:
(1) push()
(2) pop
(1) push()
stk=[]
top=None
def push():
if len(stk)==0:
stk.append(items)
top=0
else:
stk.append(items)
top=top+1
print(top)
print(“amit”)
(2) pop()
stk=[12,34]
a=stk.pop()
print(a)
print(stk)
print("amit")
Output:-
PROGRAM 15
AIM: WAP to display global and local scope?
Code:
def add(x,y):
global a
z=x+y
a=a+10
print(z)
print(a)
a=12
b=12
add(a,b)

Local():-
def add(x,y):
z= x+y
print(a,b)
print(z)
a=12
b=19
add(a,b)
print(z)
print(“amit”)

Output:-

Display() :-
stk=[10,20,30,40]
def display(stk):
for i in stk:
print(i)
print("amit")
Output:-
Program 16
Ques16. Write a program to connect Python with MySQL using
database connectivity and perform the following operations on
data in database: Fetch, Update and delete the data.
A. CREATE A TABLE
import mysql.connector
demodb = mysql.connector.connect(host="localhost", user="root",
passwd="computer", database="EDUCATION")
democursor=demodb.cursor()
democursor execute("CREATE TABLE STUDENT (admn_no int primary
key, sname varchar(30), gender char(1). DOB date, stream
varchar(15), marks float(4.2))")

B.INSERT THE DATA


import mysql.connector
demodb = mysql.connector.connect(host="localhost", user="root",
passwd="computer", database="EDUCATION") democursor
demodb.cursor() democursor.execute("insert into student values
(%s, %s, %s, %s, %s, %s)". (1245, 'Mayank Mangla'. 'M', '2007-09-11',
'science', 67.34))
demodb.commit()

C. FETCH THE DATA


import mysql.connector
demodb mysql.connector.connect(host="localhost", user="root".
passwd="computer", database="EDUCATION") democursor
demodb.cursor() democursor.execute("select from student")
for i in democursor:
print(i)
D.UPDATE THE RECORD
import mysql.connector demodb =
mysql.connector.connect(host="localhost", user="root".
passwd="computer", database="EDUCATION") democursor-
demodb.cursor() democursor.execute("update student set
marks=55.68 where admn_no=4342")
demodb.commit()
E. DELETE THE DATA
import mysql.connector
demodb = mysql.connector.connect(host="localhost", user="root".
passwd="computer", database="EDUCATION")
democursor-demodb.cursor()
democursor.execute("delete from student where admn_no=4342")
demodb.commit()
PROGRAM 17
SQL Command

Q1 create DATABASE
Syntax :

use name:

create table:
Syntax:

Q2 show database
Syntax:
show tables
Syntax:

Desc

Insert table

Q3 Alter command
Delete
Add

Update

Rename

Add primary key

Select command

To display selected coloum:


Todisplayselectedrow:

To select district row:

To select table
Select scalar expression

Logical relation

Sorting output: assending order

Descending order
Patter match

Select those student whose name letter 5:

Count of employer in a table :

PROGRAM 17
Aggregate function:
count(): select count(dept) from employee;
average(): select avg(salary) from employee;
sum(): select sum(salary) from employee;
max(): select max(salary) from employee;
min(): select min(salary) from employee;

You might also like