0% found this document useful (0 votes)
23 views47 pages

Prac File

Uploaded by

sneh71275
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)
23 views47 pages

Prac File

Uploaded by

sneh71275
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/ 47

CH.

CHHABIL DASS PUBLIC


SCHOOL,GHAZIABAD

COMPUTER SCIENCE
PRATICAL FILE

XII-B
(SESSION 2024-2025)

Submittted To : Amit Singhal Sir


Submitted By : Aryan Tyagi
Board Roll no. :
Index
Teacher
Serial No. Programs Remarks

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

10. Python Program-8

11. Python Program-9

12. Python Program-10

13. Python Program-11

14. Python Program-12

15. Python Program-13

16. Python Program-14


17. Python Program-15

18. Python Program-16

19. Python Program-17

20. Python Program-18

21. Python Program-19

22. Python Program-20

23. SQL Queries-1

24. SQL Queries-2

25. SQL Queries-3

26. SQL Queries-4


Certificate
This is to certify that Aryan Tyagi of class XII-B has prepared the
“Computer Practical File”.

This is certified to be the bonafide work of the student in Computer


Laboratory during the academic year 2024-25.

Date

(Mr. Amit Singhal)


(Computer Science Teacher)

Examiner’s Sign Principal’s Sign

School stamp
Acknowledgment
It is customary for me to acknowledge the contribution and
suggestions received from various sources.

I would like to thank Mr. Amit Singhal who gave me the


opportunity to do this practical file of Computer Science

I wish to acknowledge all the help and encouragement I received


that helped me to complete this project.
Que1: WAP to input total units which was consumed by a customer,
calculate and display total charged to be paid by the customer.
Electric Bill charges will calculate as per following condition.
No. of units Rate(in Rs) First 100 Units 1 Rs
per unit.
Next200 Units 2 Rs per unit. Above300 Units 4 Rs per
unit.

Ans: def electric_bill():

total_units = int(input("Enter the total units consumed: "))


total_charge = 0

if total_units <= 100:


total_charge = total_units * 1
elif total_units <= 300: total_charge = (100 * 1) +
((total_units - 100) * 2) else:
total_charge = (100 * 1) + (200 * 2) + ((total_units - 300) * 4)

print("Total charge to be paid: Rs", total_charge)

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.

Ans: import csv


def write_single_record(): f =
open("student.csv", "a", newline="")
writer = csv.writer(f)
header=['Roll.no','Name','Grade']
writer.writerow(header) roll_no =
input("Enter Roll No: ") name =
input("Enter Name: ") grade =
input("Enter Grade: ")
record=[roll_no, name, grade]
writer.writerow(record)
print("Single record added successfully!")
f.close()

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: "))

for i in range(0,num_students): roll_no =


int(input("Enter Roll Number: ")) name =
input("Enter Name: ") record=[roll_no ,
name] input_list.append(record)

def PushS(input_list): print("\nPushing the


students into the stack:") for student in
input_list:
student_stack.append(student)
print(student_stack)

def PopS(): print("\nPopping students from


the stack:") while True:
if student_stack == []: print("Stack is
empty") break else: print("Popped:",
student_stack.pop())

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.

Ans: import mysql.connector as mob def


create_database():
con=mob.connect(host='localhost',user='root',
password='1234')
cur=con.cursor()
cur.execute("create database Company")
print()
print("Database Created")
con.commit() con.close()
def create_table():

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()

(A) def display_record():

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()

(B) def update_record():

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;

ii. SELECT MIN(DOB) ,MAX(DOB) FROM EMPOYEE;

iii. SELECT SALARY+HRA ,SGRADE FROM SALGRADE WHERE


SGRADE = ‘S02’;
b) SELECT MIN(noofstudents) FROM SchoolBus;

c) SELECT AVG(charges) FROM SchoolBus WHERE transporter = ‘Anand


Travels’;

d) SELECT DISTINCT transporter FROM SchoolBus;

You might also like