Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Ques-1.

import pickle
def WriteScore():
fout = open("marks.dat", "wb") # opening of file
while True:
rec = {}
rollno = int(input("Enter Roll Number : "))
name = input("Enter Name : ")
marks = float(input("Enter marks : "))
rec['rollno'] = rollno
rec['name'] = name
rec['marks'] = marks
pickle.dump(rec, fout) #write one record in a file refered by fout
print()
wish = input("Wish to add more records y/n ")
if wish.lower() != 'y':
break
fout.close()
def Display_95_above():
fin = open("marks.dat", "rb")
try:
while True: # loop is required to read all records
rec = pickle.load(fin) # read only one record
# at a time refered by fin file object
if rec['marks'] > 95 :
print(rec['rollno'], rec['name'], rec['marks'])
except:
fin.close()
#__ main ___ block
print("Writing Records in Marks.dat")
WriteScore()
print("Reading Records from Marks.dat")
Display_95_above()

(ii)
import pickle
def WriteRecords():
fout = open("marks.dat", "wb") # opening of file
while True:
rec = {}
rollno = int(input("Enter Roll Number : "))
name = input("Enter Name : ")
marks = float(input("Enter marks : "))
rec['rollno'] = rollno
rec['name'] = name
rec['marks'] = marks
pickle.dump(rec, fout) #write one record in a file refered by fout
print()
wish = input("Wish to add more records y/n ")
if wish.lower() != 'y':
break
fout.close()
def CopyTopper():
fin = open("marks.dat", "rb")
fout = open("topper.dat", "wb")
try:
while True: # loop is required to read all records
rec = pickle.load(fin) # read only one record
# at a time refered by fin file object
if rec['marks'] > 95 :
pickle.dump(rec, fout)
print(rec['rollno'], rec['name'], rec['marks'])
except:
fin.close()
fout.close()
print("Copied successfully")
#__ main ___ block
print("Writing Records in marks.dat")
WriteRecords()
print("Copying Records from marks.dat to topper.dat")
CopyTopper()

Ques-2.
(i) Statement 1:
mydb = mycon.connect(host = “localhost”, user =”root”, password = “rootpass”,
database = “customer”)
(ii) Statement 2:
mycursor = mydb.cursor()
(iii) Statement 3:
mycursor.execute(“SELECT * FROM CUSTOMER”)
(iv) Statement 4:
myresult = mycursor.fetchall( )

You might also like