0% found this document useful (0 votes)
32 views6 pages

22.06.2024 Binary File Complete

hghgfjfgngj

Uploaded by

Sparsh Bhatia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views6 pages

22.06.2024 Binary File Complete

hghgfjfgngj

Uploaded by

Sparsh Bhatia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

# Q1. A binary file “Book.dat” has structure [BookNo, Book_Name, Author, Price].

# Write a user defined function CreateFile() to input data for a record and add to
# Book.dat .

import pickle
# def CreateFile():
# f=open("Book.Dat","wb")
# while True:
# bno=int(input("Enter Book Number : "))
# bname=input("Enter Book Name ")
# aname=input("Enter Author Name ")
# price=float(input("Enter Price "))
# b=[bno,bname,aname,price]
# pickle.dump(b,f)
# ch=input("Do you want to add more record Y/N ")
# if ch not in 'Yy':
# break
# f.close()

# def ReadFile():
# f=open("book.dat","rb")
# count=0
# while True:
# try:
# b = pickle.load(f)
# if b[3]>300:
# print("Book Number : ", b[0])
# print("Book Name : ", b[1])
# print("Author Name : ", b[2])
# print("Price : ", b[3])
# count = count + 1
#
# except:
# break
# print("Total No Of Records = ",count)
# f.close()
# CreateFile()
# ReadFile()

# '''Q3. A binary file “jokes.dat” has structure [Jokeid, Type, Jokedesc].


# Write a user defined function CreateFile() to input data for a record and add to
# Joke.dat at the bottom of it .'''
# import pickle
# def CreateFile():
# f=open("jokes.dat","ab")
# while True:
# jokeid=input("Enter Joke Id")
# type=input("Enter Joke Type")
# desc=input("Enter Joke Description")
# j=[jokeid,type,desc]
# pickle.dump(j,f)
# ch=input("Do you want to add more records Y/N ")
# if ch not in 'Yy':
# break
# f.close()
# CreateFile()
# def Readfile():
# f=open("jokes.dat","rb")
# while True:
# try:
# j=pickle.load(f)
# print("Joke Id ",j[0])
# print("Joke Type ",j[1])
# print("Description ",j[2])
# except:
# break
# f.close()
# Readfile()

# '''A binary file “STUDENT.DAT” has structure (admission_number, Name,


# Percentage).
# Write a function countrec() in Python that would read contents of the file
# “STUDENT.DAT” and display the details of those students whose percentage is above
# 75. Also display number of students scoring above 75%'''
# import pickle
# def CreateFile():
# f=open("student.dat","wb")
# while True:
# admno=input("Enter Admission Number ")
# name=input("Enter Student's Name ")
# percentage=float(input("Enter Percentage Marks "))
# s=[admno,name,percentage]
# pickle.dump(s,f)
# ch=input("Do you want to add more Records Y/N ")
# if ch not in 'Yy':
# break
# f.close()
# def countrec():
# f=open("student.dat","rb")
# count=0
# while True:
# try:
# s=pickle.load(f)
# if s[2]>75:
# print("Admission Number : ",s[0])
# print("Student's Name :",s[1])
# print("Percentage Marks :",s[2])
# count+=1
# except:
# break
# f.close()
# print("Total number of students having percentage marks greater than 75 =
",count)
# CreateFile()
# countrec()
#
#
# '''Q5. A binary file “PHONE.DAT” has structure (Name,Address,Areacode,Phoneno).
# Write a function TRANSFER() in Python that would copy all those records which are
# having AreaCode as "Del" from Phone.Dat to Phoneback.Dat.'''
# import pickle
# def CreateFile():
# f=open("phone.dat","wb")
# while True:
# name=input("Enter name ")
# address=input("Enter Address ")
# areacode=input("Enter Area Code ")
# phoneno = input("Enter Phone Number ")
# p=[name,address,areacode,phoneno]
# pickle.dump(p,f)
# ch=input("Do you want to add more Records Y/N ")
# if ch not in 'Yy':
# break
# f.close()
# def countrec():
# f=open("phoneback.dat","rb")
# while True:
# try:
# p=pickle.load(f)
# print("Name : ",p[0])
# print("Address :",p[1])
# print("Area Code :",p[2])
# print("Phone Number :", p[3])
# except:
# break
# f.close()
# def Transfer():
# f=open("phone.dat","rb")
# f1=open("phoneback.dat","wb")
# while True:
# try:
# p=pickle.load(f)
# if p[2]=='DEL':
# pickle.dump(p,f1)
# except:
# break
# f.close()
# f1.close()
#
# # CreateFile()
# Transfer()
# countrec()
#
#
# '''Q6. A binary file “DRINKS.DAT” has structure (Dcode,Dname,Dsize,Dprice).
# i. Write a user defined function CreateFile() to input data for a record and
# add to Drinks.dat.
# ii. Read the record of DRINKS from a binary file and display them on screen
# when DNAME has value INDYCOLA.'''
# import pickle
# def CreateFile():
# f=open("drinks.dat","wb")
# while True:
# dcode=input("Enter Dcode ")
# dname=input("Enter Dname ")
# dsize=input("Enter DSsize ")
# dprice = float(input("Enter Price "))
# d=[dcode,dname,dsize,dprice]
# pickle.dump(d,f)
# ch=input("Do you want to add more Records Y/N ")
# if ch not in 'Yy':
# break
# f.close()
# def Readfile():
# f=open("drinks.dat","rb")
# while True:
# try:
# d=pickle.load(f)
# if d[1]=='INDYCOLA':
# print("Dcode : ",d[0])
# print("Dname :",d[1])
# print("Dsize :",d[2])
# print("Dprice :", d[3])
# except:
# break
# f.close()
# CreateFile()
# Readfile()

#
# '''Q7. A binary file “Toys.DAT” has structure (Toy_code, Toy_Name, Age_range).
# Write a function in Python that would read contents of the file “Toys.DAT” and
# display the details of those Toys, which are meant for children of AgeRange "5 to
8".'''
# import pickle
# def CreateFile():
# f=open("Toys.dat","wb")
# while True:
# code=input("Enter Toy Code ")
# name=input("Enter Toy Name ")
# agerange=input("Enter Age Range ")
# t=[code,name,agerange]
# pickle.dump(t,f)
# ch=input("Do you want to add more Record Y/N ")
# if ch not in 'Yy':
# break
# f.close()
# # CreateFile()
# def ReadFile():
# f=open("Toys.dat","rb")
# while True:
# try:
# t=pickle.load(f)
# if t[2]=="5 TO 8":
# print("Toy Code ",t[0])
# print("Toy Name ",t[1])
# print("Age Range ",t[2])
# except:
# break
# f.close()
# ReadFile()
#
#
# '''Q11. A binary file “School.DAT” has structure (Scode, Sname,No_Of_Teachers).
# Write a function in Python that would read contents of the file “School.DAT”,
find
# and display the total number of teachers, whose data is stored in the file and
display
# the same.'''
# import pickle
# def CreateFile():
# f=open("School.dat","wb")
# while True:
# scode=input("Enter School Code ")
# sname=input("Enter School Name ")
# noofteachers=int(input("Enter No Of Teachers "))
# s=[scode,sname,noofteachers]
# pickle.dump(s,f)
# ch=input("Do You Want to add More Record Y/N ")
# if ch not in 'Yy':
# break
# f.close()
# # CreateFile()
# def ReadFile():
# f=open("School.dat","rb")
# total=0
# while True:
# try:
# s=pickle.load(f)
# total=total+s[2]
# print("School Code ",s[0])
# print("School Name ",s[1])
# print("No of Teachers ",s[2])
# except:
# break
# f.close()
# print("Total No of Teachers = ",total)
# ReadFile()

# # Binary File 2024 CBSE


#
# import pickle
# def CreateFile():
# f=open("item.dat","wb")
#
# while True:
# i={}
# item_id=input("Enter Item Id :" )
# item_name=input("Enter Item Name :")
# amount=float(input("Enter Amount)) :")
# i[item_id]=[item_name,amount]
# pickle.dump(i,f)
# ch=input("Do you want to add more record Y/N")
# if ch not in 'Yy':
# break
# f.close()
# def Copy_new():
# f=open("item.dat","rb")
# f1=open("item_new.dat","wb")
# while True:
# try:
# i=pickle.load(f)
# for j in i:
# if i[j][1]>1000:
# pickle.dump(i,f1)
# print(i)
# except:
# break
# f.close()
# f1.close()
#
# CreateFile()
# Copy_new()

You might also like