Python Binary File Operations and SQL Basics for High School, Assignments of Computer science

A practical guide to performing binary file operations in python, specifically focusing on creating, updating, and reading student records. It includes code snippets for adding student data (roll number, name, marks) to a binary file, updating the marks of a specific student, and displaying the details of all students. The document also covers basic sql queries for employee data management, such as displaying employee details in descending order of salary, deleting a column from a table, displaying the number of employees per city, and increasing employee salaries by 10%. This resource is useful for high school students learning about file handling and database operations. (438 characters)

Typology: Assignments

2022/2023

Available from 07/09/2025

arpit-verma-3
arpit-verma-3 🇮🇳

1 document

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1 SET - 2
Roll Number:
Name:
Date:
Class: 12
Section:
Subject: Computer Science Practical (083)
School Name: GSBV, Burari, Delhi 84
SET 02
Practical - 1:
Create a binary file with roll number, name and marks of some students. Input a roll number
and update the marks of specific student.
#First we import the pickle module to read and write the binary file in Python
import pickle
#Initialize a Empty dictionary
S={}
while True:
#Create a menu for different type of options
pf3
pf4
pf5

Partial preview of the text

Download Python Binary File Operations and SQL Basics for High School and more Assignments Computer science in PDF only on Docsity!

Roll Number:

Name:

Date:

Class: 12

Section:

Subject: Computer Science Practical (083)

School Name: GSBV, Burari, Delhi – 84

SET – 02

Practical - 1:

Create a binary file with roll number, name and marks of some students. Input a roll number and update the marks of specific student.

#First we import the pickle module to read and write the binary file in Python

import pickle

#Initialize a Empty dictionary

S={}

while True:

#Create a menu for different type of options

print("Press 1: For Add Student")

print("Press 2: For Update Student")

print("Press 3: For Exit")

#Input Choice from the user

choice = int(input("Enter Your Choice: "))

if choice == 1:

#Use open() for create and open the binary file in append mode f=open('stud.dat','ab') rno=int(input("Enter the roll no. of the student : ")) name=input("Enter the name of the student: ") marks=int(input("Enter the marks of the student: ")) S['RollNo']=rno S['Name']=name S['Marks']=marks #dump() of pickle module used to write the content in the binary file pickle.dump(S,f) #close the file using close() f.close()

elif choice ==2:

#Now open the binary file in read mode

f=open('stud.dat','rb') try: while True: S=pickle.load(f) #Display the details of the student print(S) except EOFError: f.close() else: break

Output:

Press 1: For Add Student

Press 2: For Update Student

Press 3: For Exit

Enter Your Choice: 1

Enter the roll no. of the student : 1

Enter the name of the student: Amit

Enter the marks of the student: 22

Press 1: For Add Student

Press 2: For Update Student

Press 3: For Exit

Enter Your Choice: 1

Enter the roll no. of the student : 2

Enter the name of the student: Aman

Enter the marks of the student: 18

Press 1: For Add Student

Press 2: For Update Student

Press 3: For Exit

Enter Your Choice: 1

Enter the roll no. of the student : 3

Enter the name of the student: Ankit

Enter the marks of the student: 28

Press 1: For Add Student

Press 2: For Update Student

Press 3: For Exit

Enter Your Choice: 2

Enter the roll no. of the student to be updated: 3

Enter the updated marks of the student: 25

{'RollNo': 1, 'Name': 'Amit', 'Marks': 22}