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

Set - 1.pdf

The document outlines a Computer Science practical assignment for Class 12 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 and searching students by roll number, along with SQL queries for managing student data in a database. Practical tasks also involve displaying student details, modifying table structures, and updating records in a database context.

Uploaded by

nik9721huma
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)
4 views6 pages

Set - 1.pdf

The document outlines a Computer Science practical assignment for Class 12 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 and searching students by roll number, along with SQL queries for managing student data in a database. Practical tasks also involve displaying student details, modifying table structures, and updating records in a database context.

Uploaded by

nik9721huma
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/ 6

Roll Number: 44

Name: Nikhil kumar rai

Date:

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

1 SET - 1
print("Press 1: For Add Student")

print("Press 2: For Search 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: ")

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

2 SET - 1
f=open('stud.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:

f.close()

if m==0:

print("Student not Found")

else:

break

3 SET - 1
Output:
Press 1: For Add Student

Press 2: For Search Student

Press 3: 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 Exit

Enter Your Choice: 1

Enter the Roll No. of the student : 38

Enter the Name of the student: Mohit Mathur

Press 1: For Add Student

Press 2: For Search Student

Press 3: For Exit

Enter Your Choice: 1

Enter the Roll No. of the student : 14

4 SET - 1
Enter the Name of the student: David

Press 1: For Add Student

Press 2: For Search Student

Press 3: For Exit

Enter Your Choice: 2

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

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

Press 1: For Add Student

Press 2: For Search Student

Press 3: For Exit

Enter Your Choice: 2

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

Student not Found

Press 1: For Add Student

Press 2: For Search Student

Press 3: For Exit

Enter Your Choice: 2

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

5 SET - 1
{'RollNo': 38, 'Name': 'Mohit Mathur'}

Press 1: For Add Student

Press 2: For Search Student

Press 3: For Exit

Enter Your Choice: 3

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'

6 SET - 1

You might also like