Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

SET -1

1 Write a random number generator that generates random numbers between 1 and 6 8
(simulates a dice).

import random
print("Dice game ")
print("Game starts...")
ans='y'
while ans=='y':
print("Dice rolling ")
s=random.randint(1,6)
print("You got:",s)
ans=input("Do you want to roll again the dice (y/n):")
print("See you again.. Bye")

2 Write SQL queries for (i) to (iv) 4


Table: Garment
gcode type price qty readydate
10023 Pencil Skirt 1150 25 2010-12-19
10001 Formal Shirt 1250 15 2010-01-12
10012 Baby Top 750 20 2009-04-09
10009 Shrug 1500 35 2012-12-20
10020 Frock 850 20 2012-01-01
10089 Slacks 750 10 2010-10-31

i) To display the gcode, type, Price of all garments whose qty is greater than 20.
Ans. select gcode, type, price from garment where qty>20;
ii) Add column named City to the table garment .
Ans. alter table garment add city varchar(20);
iii) Display the information in the descending order of gcode.
Ans. select * from garment order by gcode desc;
iv) Delete all the information whose gcode is 10023.
Ans. delete from garment where gcode=10023;
-2 SET
1 Read a text file line by line and display each word separated by a #. 8
a=open('sample.txt','r')
b=a.readline()
while b:
c=b.split()
for i in range(len(c)-1):
print(c[i],'#',end='')
print(c[-1])
print()
b=a.readline()
a.close()

2 Write SQL queries for (i) to (iv) 4


Table: emp

i) To display job, count of jobs by grouping similar jobs.


Ans. select job, count(job) from emp group by job;
ii)To display employee information whose comm is null.
Ans. select * from emp where comm is null;
iii)Delete the information of the table.
Ans. delete from emp;
iv)To display number of jobs from emp whose deptno is 20.
Ans. select count(job) from emp where deptno=20;
SET -3

1 Read a text file and display the number of 8


vowels/consonants/uppercase/lowercase characters in the file.

a=open('sample.txt','r')
b=a.read()
v=c=uc=lc=0
for i in b:
if i.isalpha():
if i in 'aeiouAEIOU':
v+=1
else:
c+=1
if i.isupper():
uc+=1
elif i.islower():
lc+=1
print("The number of vowels in the file is :",v)
print("The number of consonants in the file is :",c)
print("The number of upper case letters in the file is :",uc)
print("The number of lower case letters in the file is :",lc)
a.close()
2 Write SQL queries for (i) to (iv) 4
Table: garment
gcode type price qty readydate
10023 Pencil Skirt 1150 25 2010-12-19
10001 Formal Skirt 1250 15 2010-01-12
10012 Baby Top 750 20 2009-04-09
10009 Shrug 1500 35 2012-12-20
10020 Frock 850 20 2012-01-01
10089 Slacks 750 10 2010-10-31

i) Increase the price by 500 rupees.


Ans. update garment SET price=price+500;
ii) Sort the elements in ascending order of Type column.
Ans. select * from garment order by type asc;
iii) Delete all the information whose Type is NULL
Ans. delete from garment where type is null;
iv) Select all information whose garment type ends with ‘%t’.
Ans. select * from garment where type like ‘%t’;
-4 SET
1 Remove all the lines that contain the character 'a' in a file and write it to 8
another file.
f=open('sample.txt', 'r')
a=f.readlines()
f.close()
f=open('sample.txt','w')
f1=open('sample1.txt','w')
for i in a:
if ('a' in i )or ('A' in i):
f1.write(i)
else:
f.write(i)
f.close()
f1.close()
2 Write SQL queries for (i) to (iv) 4
Table: emp

i) Drop a column deptno from the table.


Ans. alter table emp drop deptno;
ii) To display all the information whose commission is not null.
Ans. select * from emp where comm is not null;
iii) Increase the commission by 5%.
Ans. update emp SET comm=comm+comm*0.50;
iv) Delete the information of employee whose job is clerk.
Ans. delete from emp where job like ‘clerk’;
SET -5
1
Create the binary file which should contains the student details and to search 8
1 the particular student based on rollno and display the details.

import pickle
def addrec():
a=open("student.bin",'wb')
print("Add student details")
l=[]
ans='y'
while ans=='y':
r=int(input("Enter the roll no:"))
n=input("Enter name :")
m=float(input("Enter mark:"))
l.append([r,n,m])
print(l)
ans=input("Do you want to add another record(y/n):")
pickle.dump(l,a)
print("Records stored successfully!.")
def searchrec():
a=open("student.bin",'rb')
r=int(input("Enter the roll no which you want to search:"))
b=pickle.load(a)
for i in b:
if r==i[0]:
print("Roll no:",i[0],"\nName:",i[1],"\nMark:",i[2])
break
else:
print("Entered Roll no not found in the file")
print("Student record search program")
addrec()
searchrec()
2 Write SQL queries for (i) to (iv) 4
Table: garment
gcode type price qty readydate
10023 Pencil Skirt 1150 25 2010-12-19
10001 Formal Skirt 1250 15 2010-01-12
10012 Baby Top 750 20 2009-04-09
10009 Shrug 1500 35 2012-12-20
10020 Frock 850 20 2012-01-01
10089 Slacks 750 10 2010-10-31

(i) To display gcode, type whose price is greater than 1000.


Ans. select gcode, type from garment where price>1000;
(ii)Update the garment table by changing the type to T-Shirt where type is formal skirt.
Ans. update garment SET type=’T-shirt’ where type like ‘formal skirt’;
iii)Display the price in descending orders.
Ans. select price from garment order by price desc;
iv)Remove the information whose skirt type ends with ‘t’.
Ans. delete from garment where type like ‘%t’;
SET -6
1 Create the binary file which should contains the student details and to update 8
the particular student based on rollno.
import pickle
def addrec():
a=open("student.bin",'wb')
print("Add student details")
l=[]
ans='y'
while ans=='y':
r=int(input("Enter the roll no:"))
n=input("Enter name :")
m=float(input("Enter mark:"))
l.append([r,n,m])
ans=input("Do you want to add another record(y/n):")
pickle.dump(l,a)
print("Records stored successfully!.")

def updaterec():
a=open("student.bin",'rb+')
r=int(input("Enter the roll no which you want to update:"))
b=pickle.load(a)
print(b)
l=[]
for i in b:
l.append(i)
for i in l:
if r==i[0]:
nm=float(input("Enter new marks:"))
i[2]=nm
break
else:
print("Entered Roll no not found in the file")
a.seek(0)
pickle.dump(l,a)
print("Record updated successfully")
print(l)
a.close()
print("Student record update program")
addrec()
updaterec()
2 Write SQL queries for (i) to (iv) 4
Table: Garment
gcode type price qty readydate
10023 Pencil Skirt 1150 25 2023-12-19
10001 Formal Shirt 1250 15 2022-01-12
10012 Baby Top 750 20 2009-04-09
10009 Shrug 1500 35 2012-12-20
10020 Frock 850 20 2012-01-01
10089 Slacks 750 10 2010-10-31

i) To display the gcode, type, Price of all garments whose qty is greater than 20.
Ans. select gcode, type, price from garment where qty>20;
ii) Add column named City to the table garment .
Ans. alter table garment add city varchar(20);
iii) Display the information in the descending order of gcode.
Ans. select * from garment order by gcode desc;
iv) Delete all the information whose gcode is 10023.
Ans. delete from garment where gcode=10023;
SET -7
1 Create the csv file which should contains the employee details and to search 8
the particular employee based on empno and display the details.

import csv
def addrec():
with open('emp.csv','a',newline='') as a:
b=csv.writer(a)
l=[]
ans='y'
while ans=='y':
eno=int(input("Enter the emp no:"))
ename=input("Enter emp name :")
s=int(input("Enter emp salary:"))
l.append([eno,ename,s])
ans=input("Do you want to add another record(y/n):")
b.writerows(l)
print("record stored")

def searchrec():
l=[]
with open('emp.csv','r') as a:
b=csv.reader(a)
s=int(input('Enter the emp no which you want to search:'))
s=str(s)
for i in b:
l.append(i)
for i in l:
if i[0]==s:
print("Emp no:",i[0],'\nEmp name :',i[1],'\nEmp salary:',i[2])
break
else:
print('no record found')

print("Employee details - search record program")


addrec()
searchrec()
2 Write SQL queries for (i) to (iv) 4
Table: emp

i) To display job, count of jobs by grouping similar jobs.


Ans. select job, count(job) from emp group by job;
ii)To display employee information whose comm is null.
Ans. select * from emp where comm is null;
iii)Delete the information of the table.
Ans. delete from emp;
iv)To display number of jobs from emp whose deptno is 20.
Ans. select count(job) from emp where deptno=20;
-8
SET
1 Write a program to implement all stack operationsusing list as stack. 8

def PUSH(stk):
a=input('Enter a city:')
stk.append(a)

def POP(stk):
if len(stk)==0:
print('STACK UNDERFLOW')
else:
c=stk.pop()
print('The popped city is:',c)

def DISPLAY(stk):
if len(stk)==0:
print('STACK EMPTY')
else:
print(stk[-1],'<--TOP')
for i in range(len(stk)-2,-1,-1):
print(stk[i])

print('STACK IMPLEMENTATION PROGRAM')


stk=[]
ans='y'
while ans.lower()=='y':
print('1-PUSH\n2-POP\n3-DISPLAY\n4-EXIT')
ch=int(input('Enter your choice:'))
if ch==1:
PUSH(stk)
elif ch==2:
POP(stk)
elif ch==3:
DISPLAY(stk)
elif ch==4:
break
ans=input('Do you want to do any operation(y/n):')
2 Write SQL queries for (i) to (iv) 4
Table: garment
gcode type price qty readydate
10023 Pencil Skirt 1150 25 2022-12-19
10001 Formal Skirt 1250 15 2021-01-12
10012 Baby Top 750 20 2010-04-09
10009 Shrug 1500 35 2012-12-20
10020 Frock 850 20 2012-01-01
10089 Slacks 750 10 2010-10-31

i) Increase the price by 500 rupees.


Ans. update garment SET price=price+500;
ii) Sort the elements in ascending order of Type column.
Ans. select * from garment order by type asc;
iii) Delete all the information whose Type is NULL
Ans. delete from garment where type is null;
iv) Select all information whose garment type ends with ‘%t’.
Ans. select * from garment where type like ‘%t’;

You might also like