Practical Answrs
Practical Answrs
1 SAMBALPUR
PRACTICAL FILE
SESSION: 2022-23
CLASS - XII
COMPUTER SCIENCE
(083)
(PYTHON / MYSQL)
17. Write a query to create the following table with Show structure of Table and Number of
Tables in Current working Database.
Table – Customer
Name of Field Datatype Size Constraints
Cno Integer 5 Primary Key
Cname Varchar 30 Not Null
Gender Char 1
DOB Date - >= “2003-01-01”
Amountpaid Float 10,2 Default “Free”
Remarks Varchar 100
18. A Stationery shop MyBag has decided to maintain its inventory of items using
MySQL. As a database administer, Rahul has created the database and table as
per the following :
Name of the database -MyBag
Name of the table - ITEMS
The attributes of ITEMS are as follows: ItemNo – Numeric, ItemName – Character of size
20 ,Scode –Numeric,Quantity –Numeric
Table: ITEMS
ItemNo ItemName Scode Quantity
19. A music store MySports is considering to maintain their inventory using SQL to store the
data. The detail is as follow:
o Name of the database – MySports
o Name of the table – Sports
The attributes of SPORTS are as follows:
SCode – character
SportName – character of size 20
Noofplayers – numeric
coachname – character of size 20
Table: SPORTS
20. Table: SPORTS
SCode SportName No. of players Coachname
1. import pickle as p
def Getdata():
f=open("Student.dat","wb")
print(e+c+p+m+c)
lst=[e,c,p,m,c]
p.dump(lst,f)
f.close()
def Calculate():
f=open("student.dat","rb")
lst=[e,c,p,m,c]
s=e+c+p+m+c
per=(s/500)*100
print("Percentage:",per)
if per>90:
grd="A1"
elif per>=75:
grd="A"
elif per>=60:
grd="B"
elif per>=45:
grd="C"
elif per>33:
grd="D"
elif per<=33:
grd="E"
else:
grd="--Padh le--"
print("Grade:",grd)
2. import random as r
def Generate():
a=r.randint(1,10)
return a
def GetNum():
a=Generate()
if a==b:
else:
3. import pickle as p
def AddStudents():
f=open("Student.dat","wb")
per=(mk/100)*100
lst=[rno,nm,mk,per]
p.dump(lst,f)
f.close()
def GetStudents():
f=open("Student.dat","rb")
while True:
try:
rec=p.load(f)
if rec[3]>75:
print(rec)
else:
except EOFError:
break
f.close()
5. def COUNTLINES():
f=open("Report.txt","r")
c=0
if word=="%E" or "%T":
c=c+1
print(c)
f.close()
6. import pickle as p
def DisplayAvgMarks():
f=open("TEST.dat","wb")
d=f.load()
s=0
n=0
for i in d:
s+=i[3]
n+=1
avmrk=s/n
7. import pickle as p
def CreateFile():
f=open("Book.dat","wb")
l=[At,bk]
p.dump(l,f)
f.close()
f=open("Book.dat","rb")
while True:
try:
d=p.load(f)
print(d[0],"\t",d[1])
except EOFError:
break
f.close()
def CountRec(Author):
f=open("Book.dat","rb")
r=p.load(f)
c=0
for i in r:
if r[0]==Author:
c=c+1
print(c)
f.close()
8. print(“Menu”)
print(“1.Add”)
print(“2.Display”)
print("3.Update")
print("4.Delete")
print("5.Search")
#Display(T)
elif n==2:
mycur=mydb.cursor() dataset=mycur.execute("Select * from
Employee, Department where
Employee.Dept_ID=Department.DeptID")
for i in mycur:
print(i)
#Update
elif n==3:
a=input("Enter Employee ID which needs to be updated:")
b=input("Enter Employee Name:") c=input("Enter
Salary:") d=input("Enter DeptID:")
e=input("Enter DeptName:") f=input("Enter
Bonus:") g=input("Enter Location:")
mycur=mydb.cursor()
dataset=mycur.execute("Update Employee, Department set
EmpName='"+b+"', Salary='"+c+"', Dept_ID='"+d+"',
DeptName='"+e+"', Bonus='"+f+"', Location='"+g+"' where
EmpID='"+a+"' and Employee.Dept_ID=Department.DeptID")
print("Data Updated Successfully.")
#Delete
elif n==4:
a=input("Enter Employee ID which you want to delete:")
mycur=mydb.cursor() dataset=mycur.execute("Delete from
Employee
where EmpID='"+a+"'")
print("Data Deleted Successfully.") print("Updated
Table") mycur1=mydb.cursor()
dataset=mycur1.execute("Select * from Employee,
Department where
Employee.Dept_ID=Department.DeptID")
for i in mycur1:
print(i)
#Search
elif n==5:
x=input("Enter Employee Name:") mycur=mydb.cursor()
dataset=mycur.execute("Select * from Employee,
Department where EmpName='"+x+"' and
Employee.Dept_ID=Department.DeptID")
for i in mycur:
print(i)
cur=mydb.cursor()
for i in a:
print(a)
Print(“Added Successfully”)
def Pop(Book):
Book=Book.pop()
Print(“Popped Successfully”)
stk.append(item)
top=len(stk)-1
def pop(stk):
if (isempty(stk)):
return ('underflow')
else:
i=stk.pop()
if (len(stk)==0):
top=None
else:
top=top[s]-1
return i
Lnameage = []
def push_na():
for x in range(len(Lname)):
Lnameage.append((Lname[x], Lage[x]))
print(Lnameage)
def pop_na():
if len(Lnameage) == 0:
print("Underflow")
else:
t = Lnameage.pop()
push_na()
pop_na()
13. CStack=[ ]
def AddCustomer(Customer):
CStack.append(Customer)
if len(CStack)==0:
print (“Empty Stack”)
else:
print (CStack)
14. CStack=[ ]
def DeleteCustomer():
if (CStack ==[]):
print(“There is no customer”)
else:
print(“Record deleted, CStack.pop())
16.i.
Firstname Salary
Rachel 32000
Peter 28000
ii.
Designation
Manager 3
Director 1
Salesman 2
clerk 1
iii.
Designation Sum(salary)
Manager 215000
iv.
6500
v. Equi join:-
17. create table Customer Cno int(5) primary key, Cname varchar(30)
notnull, Gender char(1), DOB date(>=2003-01-01), Amountpaid float(10,2),
Remark varchar(100);
18. create table Sports Scode char, SportName char(20), Noofplayers int,
coachname char(20);
b. desc SPORTS;
CountRec(Author)
8.
9.
10
11. stk=[1,2,3,4]
push(stk,5)
print(stk)
[1, 2, 3, 4, 5]