0% found this document useful (0 votes)
5 views8 pages

Python Assignment: #Source Code

The document contains a Python program for managing student marks using binary files. It allows users to append records, display all records, count records based on theory marks, and search for records by roll number. The program utilizes the pickle module for serialization and deserialization of data.

Uploaded by

vratteshanand308
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)
5 views8 pages

Python Assignment: #Source Code

The document contains a Python program for managing student marks using binary files. It allows users to append records, display all records, count records based on theory marks, and search for records by roll number. The program utilizes the pickle module for serialization and deserialization of data.

Uploaded by

vratteshanand308
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/ 8

PYTHON ASSIGNMENT

#VRATTESH ANAND
#CLASS-12 SECTION-B
#ROLL NO:35
#Q12:
#SOURCE CODE:

import pickle
def BINARY_1():
f=open("MARKS.DAT",'ab')
rec=[]
for k in range(2):
roll=int(input("enter a roll"))
name=input("enter a name")
theo=eval(input("enter a theory marks "))
prac=eval(input("enter a practical marks"))
TTOT=eval(input("enter a total"))
rec+=[roll,name,theo,prac,TTOT]
pickle.dump(rec,f)

f.close()

import pickle
def BINARY_2():
f=open("MARKS.DAT",'rb')
c=0
while True:
try:
v=pickle.load(f)
c+=1
print(v)
except:
print('all records done')

break
print(c)
f.close()

import pickle
def BINARY_3():
f=open("MARKS.DAT",'rb')
c=0
n=int(input("enter loops"))
while True:
try:
v=pickle.load(f)
for k in range(n):
if v[2]>=63:
c+=1
print(v)

except:
print('all records done')

break
f.close()

import pickle
def BINARY_4():
f=open("MARKS.DAT",'rb')
c=0
ROLL=int(input("enter roll"))
while True:
try:
v=pickle.load(f)
if v[0]==ROLL:
print("rec found and searched")

print(v)

except:

print('all records done')


break

f.close()

while True:

print("=========================================menu============
================================================")

print("1.APPEND THE RECORDS")


print("2.DISPLAY AND READ THE BINARY FILE AND COUNT RECORDS
")
print("3.DISPLAY THE NUMBER OF RECORDS WITH INPUTTED THEORY
")
print("4.DISPLAY THE NUMBER OF RECORDS WITH INPUTTED ROLL")
print("0.EXIT FROM MENU")

ch=int(input("ENTER AN OPTION"))

if ch==1:
BINARY_1()
elif ch==2:
BINARY_2()
elif ch==3:
BINARY_3()
elif ch==4:
BINARY_4()
elif ch==0:
print("breaking from menu... BYE")
break

else:
print('object not found , OPTION not found')

#OUTPUT:
'''
Python 3.13.2 (tags/v3.13.2:4f8bb39, Feb 4 2025, 15:23:48) [MSC
v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more
information.

==================== RESTART: E:\PYTHON-FILES\question12.py


====================
=========================================menu===================
=========================================
1.APPEND THE RECORDS
2.DISPLAY AND READ THE BINARY FILE AND COUNT RECORDS
3.DISPLAY THE NUMBER OF RECORDS WITH INPUTTED THEORY
4.DISPLAY THE NUMBER OF RECORDS WITH INPUTTED ROLL
0.EXIT FROM MENU
ENTER AN OPTION1
enter a roll29
enter a nameSIDDHARTH DAS
enter a theory marks 51.0
enter a practical marks27.0
enter a total78.0
enter a roll30
enter a nameSUDHIR SINGH
enter a theory marks 64.0
enter a practical marks30.0
enter a total94.0
=========================================menu===================
=========================================
1.APPEND THE RECORDS
2.DISPLAY AND READ THE BINARY FILE AND COUNT RECORDS
3.DISPLAY THE NUMBER OF RECORDS WITH INPUTTED THEORY
4.DISPLAY THE NUMBER OF RECORDS WITH INPUTTED ROLL
0.EXIT FROM MENU
ENTER AN OPTION2
[1, 'SIDDHARTH GUPTA', 53.0, 28.0, 81.0]
[2, 'AREEB AHMED', 47.0, 24.0, 71.0]
[3, 'ADITI SINGH', 46.0, 25.0, 71.0]
[4, 'AJAY RANA', 40.0, 26.0, 66.0]
[5, 'ANAM AFROZ', 54.0, 29.0, 83.0]
[6, 'ANUSHA JAIN', 50.0, 27.0, 77.0]
[7, 'ARUN NITESH', 66.0, 30.0, 96.0]
[8, 'ASHWIN GUPTA', 47.0, 26.0, 73.0]
[9, 'ASTRID JERALD', 60.0, 30.0, 90.0]
[10, 'SANJANA IRANI', 54.0, 27.0, 81.0]
[11, 'HAIDER SHAHED', 43.0, 23.0, 66.0]
[12, 'PRINCE KEVIN', 37.0, 27.0, 64.0]
[13, 'LAKSHMY KRISHNAN', 62.0, 30.0, 92.0]
[14, 'SAMEER PRASAD', 54.0, 29.0, 83.0]
[15, 'MADHU SRAVAN', 40.0, 23.0, 63.0]
[16, 'MANSI JOSEPH', 50.0, 24.0, 74.0]
[17, 'MANOJ SHARMA', 58.0, 30.0, 88.0]
[18, 'MUKUL BHAGWAT', 57.0, 25.0, 82.0]
[19, 'NIKHIL NAND', 63.0, 30.0, 93.0]
[20, 'PRERNA GHOSH', 62.0, 30.0, 92.0]
[21, 'RITWIK KISHORE', 58.0, 30.0, 88.0]
[22, 'ROZANE MATHEW', 53.0, 27.0, 80.0]
[23, 'RAVI AHUJA', 48.0, 26.0, 74.0]
[24, 'SANA SANDEEP', 56.0, 28.0, 84.0]
[25, 'SHAGHUN CHAUHAN', 40.0, 24.0, 64.0]
[26, 'SHANTANU JHA', 64.0, 30.0, 94.0]
[27, 'SOUMEN RAY', 60.0, 30.0, 90.0]
[28, 'SRUTHI KANNAN', 57.0, 30.0, 87.0]
[29, 'SIDDHARTH', 51.0, 27.0, 78.0]
[29, 'SIDDHARTH', 51.0, 27.0, 78.0, 30, 'SUDHIR SINGH', 64.0,
30.0, 94.0]
[11, 'vrat', 78, 88, 196]
[11, 'vrat', 78, 88, 196, 12, 'vrate', 45, 30, 75]
[29, 'SIDDHARTH DAS', 51.0, 27.0, 78.0]
[29, 'SIDDHARTH DAS', 51.0, 27.0, 78.0, 30, 'SUDHIR SINGH',
64.0, 30.0, 94.0]
[29, 'SIDDHARTH DAS', 51.0, 27.0, 78.0]
[29, 'SIDDHARTH DAS', 51.0, 27.0, 78.0, 30, 'SUDHIR SINGH',
64.0, 30.0, 94.0]
all records done
36
=========================================menu===================
=========================================
1.APPEND THE RECORDS
2.DISPLAY AND READ THE BINARY FILE AND COUNT RECORDS
3.DISPLAY THE NUMBER OF RECORDS WITH INPUTTED THEORY
4.DISPLAY THE NUMBER OF RECORDS WITH INPUTTED ROLL
0.EXIT FROM MENU
ENTER AN OPTION3
enter loops2
[1, 'SIDDHARTH GUPTA', 53.0, 28.0, 81.0]
[2, 'AREEB AHMED', 47.0, 24.0, 71.0]
[3, 'ADITI SINGH', 46.0, 25.0, 71.0]
[4, 'AJAY RANA', 40.0, 26.0, 66.0]
[5, 'ANAM AFROZ', 54.0, 29.0, 83.0]
[6, 'ANUSHA JAIN', 50.0, 27.0, 77.0]
[7, 'ARUN NITESH', 66.0, 30.0, 96.0]
[8, 'ASHWIN GUPTA', 47.0, 26.0, 73.0]
[9, 'ASTRID JERALD', 60.0, 30.0, 90.0]
[10, 'SANJANA IRANI', 54.0, 27.0, 81.0]
[11, 'HAIDER SHAHED', 43.0, 23.0, 66.0]
[12, 'PRINCE KEVIN', 37.0, 27.0, 64.0]
[13, 'LAKSHMY KRISHNAN', 62.0, 30.0, 92.0]
[14, 'SAMEER PRASAD', 54.0, 29.0, 83.0]
[15, 'MADHU SRAVAN', 40.0, 23.0, 63.0]
[16, 'MANSI JOSEPH', 50.0, 24.0, 74.0]
[17, 'MANOJ SHARMA', 58.0, 30.0, 88.0]
[18, 'MUKUL BHAGWAT', 57.0, 25.0, 82.0]
[19, 'NIKHIL NAND', 63.0, 30.0, 93.0]
[20, 'PRERNA GHOSH', 62.0, 30.0, 92.0]
[21, 'RITWIK KISHORE', 58.0, 30.0, 88.0]
[22, 'ROZANE MATHEW', 53.0, 27.0, 80.0]
[23, 'RAVI AHUJA', 48.0, 26.0, 74.0]
[24, 'SANA SANDEEP', 56.0, 28.0, 84.0]
[25, 'SHAGHUN CHAUHAN', 40.0, 24.0, 64.0]
[26, 'SHANTANU JHA', 64.0, 30.0, 94.0]
[27, 'SOUMEN RAY', 60.0, 30.0, 90.0]
[28, 'SRUTHI KANNAN', 57.0, 30.0, 87.0]
[29, 'SIDDHARTH', 51.0, 27.0, 78.0]
[29, 'SIDDHARTH', 51.0, 27.0, 78.0, 30, 'SUDHIR SINGH', 64.0,
30.0, 94.0]
[11, 'vrat', 78, 88, 196]
[11, 'vrat', 78, 88, 196, 12, 'vrate', 45, 30, 75]
[29, 'SIDDHARTH DAS', 51.0, 27.0, 78.0]
[29, 'SIDDHARTH DAS', 51.0, 27.0, 78.0, 30, 'SUDHIR SINGH',
64.0, 30.0, 94.0]
[29, 'SIDDHARTH DAS', 51.0, 27.0, 78.0]
[29, 'SIDDHARTH DAS', 51.0, 27.0, 78.0, 30, 'SUDHIR SINGH',
64.0, 30.0, 94.0]
all records done
=========================================menu===================
=========================================
1.APPEND THE RECORDS
2.DISPLAY AND READ THE BINARY FILE AND COUNT RECORDS
3.DISPLAY THE NUMBER OF RECORDS WITH INPUTTED THEORY
4.DISPLAY THE NUMBER OF RECORDS WITH INPUTTED ROLL
0.EXIT FROM MENU
ENTER AN OPTION4
enter roll12
rec found and searched
[12, 'PRINCE KEVIN', 37.0, 27.0, 64.0]
all records done
=========================================menu===================
=========================================
1.APPEND THE RECORDS
2.DISPLAY AND READ THE BINARY FILE AND COUNT RECORDS
3.DISPLAY THE NUMBER OF RECORDS WITH INPUTTED THEORY
4.DISPLAY THE NUMBER OF RECORDS WITH INPUTTED ROLL
0.EXIT FROM MENU
ENTER AN OPTION0
breaking from menu... BYE
'''

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy