Set 1 - Bin Search
Set 1 - Bin Search
i. Display the rollno,age,gname from students and sports with gname contains ‘R’
ii. Display the gender wise average of total from the students table.
iii. Display the age,dob and gender of students who’s DOB is given and age more than 15.
iv. Display the sname and gender of students who’s age is neither 12 nor 22.
Q2. Practical Report File 7
Q3. Project 8
Q4. Viva Voce 3
Solution:
import pickle
def addrec():
f=open("shoes.dat","ab")
s_id=int(input("Enter Shoes ID:"))
name=input("Enter shoes name:")
brand=input("Enter Brand:")
typ=input("Enter Type:")
price=float(input("Enter Price:"))
l=[s_id,name,brand,typ,price]
pickle.dump(l,f)
print("Record Added Successfully.")
f.close()
def disprec():
f=open("shoes.dat","rb")
while True:
try:
dt=pickle.load(f)
print(dt)
except EOFError:
break
f.close()
def searchrec():
si=int(input("Enter shoes ID:"))
f=open("shoes.dat","rb")
fl=False
while True:
try:
dt=pickle.load(f)
for i in dt:
if i==si:
fl=True
print("Record Found...")
print("ID:",dt[0])
print("Name:",dt[1])
print("Brand:",dt[2])
print("Type:",dt[3])
print("Price:",dt[4])
except EOFError:
break
if fl==False:
print("Record not found...")
f.close()
while True:
print('''
1. Add Record
2. Display Record
3. Search Record
4. Exit
''')
ch=int(input("Enter your choice:"))
l=[]
if ch==1:
addrec()
elif ch==2:
disprec()
elif ch==3:
searchrec()
elif ch==4:
break
else:
print("Invalid Choice")
b. SQL
Table Creation:
i. Display the rollno,age,gname from students and sports with gname contains ‘R’
ii. Display the gender wise average of total from the students table.
iii. Display the age,dob and gender of students who’s DOB is given and age more than 15.
iv. Display the sname and gender of students who’s age is neither 12 nor 22.