0% found this document useful (0 votes)
112 views3 pages

Program 13. Binary File 1 Aim

The document describes a program that creates a binary file containing student records with details like roll number, name, stream, and total marks. The program allows the user to display the topper from each stream and increment/decrement marks for certain streams. It takes student input to populate the file, displays toppers, allows modifying marks, and closes the file.

Uploaded by

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

Program 13. Binary File 1 Aim

The document describes a program that creates a binary file containing student records with details like roll number, name, stream, and total marks. The program allows the user to display the topper from each stream and increment/decrement marks for certain streams. It takes student input to populate the file, displays toppers, allows modifying marks, and closes the file.

Uploaded by

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

PROGRAM 13.

BINARY FILE 1
AIM:
Write a program to create a binary file STUDENT.DAT/.BIN/.TXT with each record having
details of rollnumber ,name, stream and total. Perform the following operations using a
menu :
1. Display Stream wise topper detail
2. Increment the total by 3 marks for students in the biology stream and decrement by
2for students in EG stream.

PROGRAM CODING:

import pickle
f=open('STUDENT.dat','wb')
st=[]
print("Enter atleast one record for each stream")
while True:
roll=int(input('Enter roll no : '))
name=input('Enter name : ')
stream=input('Enter stream(cs/bio/eg/market) : ')
marks=int(input('Enter total marks : '))
st.append([roll,name,stream,marks])
ch=input('Do u wanto to continue (y/n): ')
if ch.lower()=='n':
break
pickle.dump(st,f)
print('MENU\n1.display topper detail wrt each stream\n2.increment 3 marks for student
in bio and decrement 2 marks for student in eg stream\n3.exit')
while True:
ch=int(input('Enter choice : '))
if ch==1:
p,bi,e,m=[],[],[],[]
for i in range(len(st)):
if st[i][2]=='cs':
p.append(st[i][3])
elif st[i][2]=='market':
m.append(st[i][3])
elif st[i][2]=='bio':
bi.append(st[i][3])
elif st[i][2]=='eg':
e.append(st[i][3])
a,b,c,d=max(p),max(m),max(bi),max(e)
for i in range(len(st)):
if a==st[i][3] and st[i][2]=='cs':
print('Details of topper in cs : ',st[i])
elif b==st[i][3] and st[i][2]=='market':
print('Details of topper in market : ',st[i])
elif c==st[i][3] and st[i][2]=='bio':
print('Details of topper in bio : ',st[i])
elif d==st[i][3] and st[i][2]=='eg':
print('Details of topper in eg : ',st[i])
elif ch==2:
for i in range(len(st)):
if st[i][2]=='bio':
st[i][3]+=3
elif st[i][2]=='eg':
st[i][3]-=2
print(st)
pickle.dump(st,f)
elif ch==3:
print('Program terminated')
f.close()
break
else:
print('Wrong choice')
OUTPUT
Enter atleast one record for each stream
Enter roll no : 1201
Enter name : shrawan
Enter stream(cs/bio/eg/market) : cs
Enter total marks : 498
Do u wanto to continue (y/n): y
Enter roll no : 1301
Enter name : akilesh
Enter stream(cs/bio/eg/market) : bio
Enter total marks : 456
Do u wanto to continue (y/n): y
Enter roll no : 1305
Enter name : srivatsan
Enter stream(cs/bio/eg/market) : eg
Enter total marks : 487
Do u wanto to continue (y/n): y
Enter roll no : 1501
Enter name : shrinitin
Enter stream(cs/bio/eg/market) : market
Enter total marks : 489
Do u wanto to continue (y/n): y
Enter roll no : 1207
Enter name : arav
Enter stream(cs/bio/eg/market) : cs
Enter total marks : 256
Do u wanto to continue (y/n): n
MENU
1.display topper detail wrt each stream
2.increment 3 marks for student in bio and decrement 2 marks for student in eg stream
3.exit
Enter choice : 1
Details of topper in cs : [1201, 'shrawan', 'cs', 498]
Details of topper in bio : [1301, 'akilesh', 'bio', 456]
Details of topper in eg : [1305, 'srivatsan', 'eg', 487]
Details of topper in market : [1501, 'shrinitin', 'market', 489]
Enter choice : 2
[[1201, 'shrawan', 'cs', 498], [1301, 'akilesh', 'bio', 459], [1305, 'srivatsan', 'eg', 485],
[1501, 'shrinitin', 'market', 489], [1207, 'arav', 'cs', 256]]
Enter choice : 3
Program terminated

You might also like