Prac File
Prac File
COMPUTER SCIENCE
PRATICAL FILE
XII-B
(SESSION 2024-2025)
1. Certificate
2. Acknowledgment
3. Python Program-1
4. Python Program-2
5. Python Program-3
6. Python Program-4
7. Python Program-5
8. Python Program-6
9. Python Program-7
Date
School stamp
Acknowledgment
It is customary for me to acknowledge the contribution and
suggestions received from various sources.
electric_bill()
Que17: Write a menu-driven program implementing user-defined
functions to perform different functions on a csv file “student”
such as:
(a) Write a single record to csv.
(b) Write all the records in one single go onto the csv.
(c) Display the contents of the csv file.
def write_multiple_records(): f =
open("student.csv", "w", newline="")
writer = csv.writer(f)
header=['Roll.no','Name','Grade']
writer.writerow(header)
num_records = int(input("Enter the number of records you
want to add: "))
for i in range(num_records): roll_no
= input("Enter Roll No: ") name
= input("Enter Name: ") grade =
input("Enter Grade: ")
record=[roll_no, name, grade]
writer.writerow(record)
print("All records added successfully!")
f.close()
def display_csv_contents():
try:
f = open("student.csv", "r") reader
= csv.reader(f) print("\nContents
of 'student.csv':") for row in
reader:
Que19: Write a program to create a stack called student, to perform the
basic operations on stack using list. The list contains two data
values called roll number and name of student. Notice that the
data manipulation operations are performed as per the rules of a
stack.
Write the following functions :
• PUSH ( ) - To push the data values (roll no. and name) into the
stack.
• POP() - To remove the data values from the stack.
• SHOW() - To display the data values (roll no. and name) from the
stack.
Ans: student_stack = []
input_list=[] num_students = int(input("Enter the number
of students: "))
def ShowS():
print("\nStudents in Stack:") for student in
student_stack: print("Roll No:",student[0],
"Name:",student[1]) else:
print("Shown all details of student.")
PushS(input_list)
ShowS()
PopS()
Que20: ABC Infotech Pvt. Ltd. needs to store, retrieve and delete the
records of its employees. Develop an interface that provides front-
end interaction through Python, and stores and updates records
using MySQL. The operations on MySQL table “emp” involve
reading, searching, updating and deleting the records of employees.
(a) Program to read and fetch all the records from EMP table
having salary more than 70000.
(b) Program to update the records of employees by increasing
salary by 1000 of all those employees who are getting less than
80000.
(c) Program to delete the record on the basis of inputted salary.
con=mob.connect(host='localhost',user='root',password='1234',d
atabase='Company')
cur=con.cursor()
cur.execute("create table emp(Id int primary key, Name
varchar(20), Salary float(7,2) ,City varchar(20))")
con.commit()
con.close() def
add_table():
con=mob.connect(host='localhost',user='root',passwd='1234',dat
abase='Company')
cur=con.cursor()
cur.execute("INSERT into emp (Id, Name, Salary,
City)
VALUES (1002 ,'Raj' ,75000.00 ,'Mumbai')")
cur.execute("INSERT into emp (Id, Name, Salary, City)
VALUES (1003 ,'Ramesh' ,80000.50 ,'Pune')")
cur.execute("INSERT into emp (Id, Name, Salary, City)
VALUES ( 1004 , 'Rajesh' ,50000.00 ,'Kota')")
cur.execute("INSERT into emp (Id, Name, Salary, City)
VALUES (1005 ,'Rajnish' ,45000.00 ,'Bengaluru')")
con.commit() con.close()
con=mob.connect(host='localhost',user='root',passwd='1234',dat
abase='Company')
cur=con.cursor()
cur.execute("SELECT * FROM emp WHERE
salary >
70000") records =
cur.fetchall() for
record in records:
print(record)
con.commit()
con.close()
con=mob.connect(host='localhost',user='root',passwd='1234',dat
abase='Company') cur = con.cursor()
cur.execute("UPDATE emp SET salary = salary +
1000
WHERE salary < 80000")
print("Salaries updated successfully")
cur.execute("SELECT * FROM emp")
records = cur.fetchall()
for record in records:
print(record)
con.commit()
con.close()
(C) def delete_record():
con=mob.connect(host='localhost',user='root',passwd='1234',dat
abase='Company')
cur = con.cursor() salary_to_delete = float(input("Enter
salary to delete: "))
cur.execute("DELETE FROM emp WHERE salary =
",
B)
i. SELECT COUNT(SGRADE) ,SGRADE FROM EMPLOYEE GROUP BY
SGRADE;