0% found this document useful (0 votes)
7 views

Set - 1

The document outlines a practical assignment for Class 12 Computer Science students, focusing on creating and managing a binary file to store student names and roll numbers using Python's pickle module. It includes a menu-driven program for adding, searching, and displaying student records. Additionally, it covers SQL operations such as sorting, deleting a column, counting students by city, and updating a student's city in a database.

Uploaded by

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

Set - 1

The document outlines a practical assignment for Class 12 Computer Science students, focusing on creating and managing a binary file to store student names and roll numbers using Python's pickle module. It includes a menu-driven program for adding, searching, and displaying student records. Additionally, it covers SQL operations such as sorting, deleting a column, counting students by city, and updating a student's city in a database.

Uploaded by

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

Roll Number: 26668843

Name: Bhavishya

Date: 20 January 2025

Class: 12

Section: A

Subject: Computer Science Practical (083)

School Name: GSBV, Burari, Delhi – 84

SET - 01

Practical - 1:

Create a binary file with name and roll number of students. Search for a given roll number

and display the name of student, if not found display appropriate message

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

import pickle

#Initialize an Empty dictionary

S={}

while True:

#Create a menu for different type of

options print("Press 1: For Add Student")

print("Press 2: For Search Student")

print("Press 3: For Display All Student")

print("Press 4: For Exit")

1 SET - 1
#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('stud2.dat','ab')

rno=int(input("Enter the Roll No. of the student : "))

name=input("Enter the Name of the student: ")

S['RollNo']=rno

S['Name']=name

#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('stud2.dat','rb')

rno=int(input("Enter the Roll no. of the student to be search: "))

K={}

m=0

try:

while True:

#load() of pickle module use to read the binary file

K=pickle.load(f)

if K["RollNo"] == rno:

#Display the details of the student

print(K)

m=m+1

except EOFError:

2 SET - 1
f.close()

if m==0:

print("Student not Found")

elif choice ==3:

f=open('stud2.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 Search Student

Press 3: For Display All Student

Press 4: For Exit

Enter Your Choice: 1

Enter the Roll No. of the student : 1

Enter the Name of the student: Mohit

Press 1: For Add Student

Press 2: For Search Student

Press 3: For Display All Student

Press 4: For Exit

Enter Your Choice: 1

Enter the Roll No. of the student : 2

3 SET - 1
Enter the Name of the student: Rohit

Press 1: For Add Student

Press 2: For Search Student

Press 3: For Display All Student

Press 4: For Exit

Enter Your Choice: 1

Enter the Roll No. of the student : 3

Enter the Name of the student: Amit

Press 1: For Add Student

Press 2: For Search Student

Press 3: For Display All Student

Press 4: For Exit

Enter Your Choice: 3

{'RollNo': 1, 'Name': 'Mohit'}

{'RollNo': 2, 'Name': 'Rohit'}

{'RollNo': 3, 'Name': 'Amit'}

Press 1: For Add Student

Press 2: For Search Student

Press 3: For Display All Student

Press 4: For Exit

Enter Your Choice: 2

Enter the Roll no. of the student to be search: 2

{'RollNo': 2, 'Name': 'Rohit'}

Press 1: For Add Student

Press 2: For Search Student

Press 3: For Display All Student

Press 4: For Exit

Enter Your Choice: 4

4 SET - 1
Practical - 2:
(a) Display the details of class XII students in descending order of their marks.

Select * from RESULT Order by Marks desc;

(b) Delete the column “Gender” from the table.

Alter Table RESULT drop column Gender;

(c) Display the city with number of students belongs to that city.

Select City, count(City) As 'Number Of Students' From RESULT Group By

City;

(d) Change the city of ‘Gauri’ from ‘Jaipur’ to ‘Noida’.

Update RESULT Set City='Noida' Where Name = 'Gauri';

5 SET - 1

You might also like