[go: up one dir, main page]

0% found this document useful (0 votes)
7 views38 pages

Computer Science Project

This document is a practical file for a computer science project submitted by students Kanav Garg and Kushal Tiwari at CH. CHHABIL DASS PUBLIC SCHOOL. It includes various programming tasks in Python, such as calculating electric bills, area of shapes, checking for prime numbers, and managing lists, among others. The project aims to demonstrate the students' understanding of Python programming concepts and their application in real-world scenarios.

Uploaded by

sadtimes7822
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 views38 pages

Computer Science Project

This document is a practical file for a computer science project submitted by students Kanav Garg and Kushal Tiwari at CH. CHHABIL DASS PUBLIC SCHOOL. It includes various programming tasks in Python, such as calculating electric bills, area of shapes, checking for prime numbers, and managing lists, among others. The project aims to demonstrate the students' understanding of Python programming concepts and their application in real-world scenarios.

Uploaded by

sadtimes7822
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/ 38

CH.

CHHABIL DASS PUBLIC SCHOOL , Patel Nagar Ghaziabad

COMPUTER SCIENCE PRACTICAL FILE


SESSION – 2024 - 2025
CLASS :- 12 – B

SUBMITTED TO :- AMIT SINGHAL SIR

SUBMITTED BY :- Kanav Garg


SUBMITTED BY :- KUSHAL TIWARI

BOARD ROLL NO. :-


CERTIFICATE

It is to certify that
KKUASNHAAL of class XII-B have completed Their computer science project
under my supervision.
VTIGWAARThey
RI have taken proper care of and shown utmost
Sincerity in completion of this project.

II certify that his project is upto my expectation as Per the guidelines issued by C.B.S.E .

MR. AMIT SINGHAL


ACKNOWLEDGEMENT

We would like to express my gratitude to my teacher MR. AMIT SINGHAL sir


who gave me this golden opportunity to form This wonderful project on the
topic “SCHOOL MANAGEMENT SYSTEM”, while working on this project We
came to know about so many new things.

Secondly, I would like to thank my parents and friends who helped me a lot
in finalising this project within the limited time frame.

Regards,

KUSHAL TIWARI
Kanav
Garg
Q-1:- 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-1 :-
Def
calculate(un
its): If units
<= 100:
T=
units*1 elif
units
<=300:
T= 100*1 + (units-
100)*2 else :
T = 100*1 + 200*2 + (units-300)*4
return T
units = int(input(“Enter the
units : “)) b = calculate
(units)
print (b)

INPUT :-
Enter the units : 100

Output :-
You have to pay Rs. 100
Q-2 – Write a menu driven program to
calculate: Area of circle[A=πr2]
Area of squire [A=a*a]
Area of rectangle[A=l*b]

Ans-2 –
Def circle (a):

A = 3.14*a**2
b = float(input(“Enter the radius : ”))
print(b)
def square (c):

A = c*c
d = float(input(“Enter the side : ”))
print(d)
def rectangle (e,f):
A = e*f

g = float(input(“Enter the length : ”))


h = float(input(“Enter the breath : ”))
print(g)
print(h)
While True:
print(“1,for area of circle”)
print(“2,for area of square”)
print(“3,for area of rectangle”)
print(“4,for exit”)
Choise = int(input(“Enter the choise : “))
If Choise == 1 :
circle(b)
elif Choise == 2:
square(d)
elif Choise == 3:
rectangle(g,h)
elif Choise == 4 :
break
else :
print(“You have entered the wrong choice “)

Input :-
Enter your choise : 3

Output :-
Enter length : 3.0
Enter breath :
4.0 12.0
Q–3–
Write a UDF in python , it will take a number as a function argument . Function check and
display whether the number if prime or not.
Ans-3 –
def check (a):
if a>1 :
for i in range (2,(a//2)+1)
: if (a%i) == 0 :
print(“The no. Is not Prime no.”)
break
else :
print(“The no. Is prime no.”)
else :
print(“The no. Is not prime no.”)
b = int(input(“Enter the no.”))
check (b)

Input :-
Enter the no. : 3

Output :-

The no. Is a prime no.


Q-4 - Write a UDF in python , it will take a number as a function argument . Function calculate
and display sum of each digit of that given number. For example: number is 456, Sum is
4+5+6= 15

Ans-4 –
def sum(a):
b=0
for i in str(a):
b+= int(a)
return b
c= int(input(“Enter no. :”))
print(c)

Input :-

Enter no. : 234

Output :-

9
Q-5 -
Write a program in python ,count and display the number of vowels, Consonants, uppercase,
lower case characters in string.
Ans- 5 –
a = input(“Enter the statement”)
b=0
c=0

d=0
e=0
f = a.split()
for i in f :
if i in “
aeiou”: b+=
i print(b)
elif i not in “aeiou”:
c+= i
print(c)
elif i.isupper == True :
d+ = i
print(d)
elif i.islower == True:
e+= i
print(e)
Input :-

Enter statement : Computer project


Output :-
Computer project
Q-6 Write a UDF in python, it will take three arguments list(sequence of elements), Its size
and finding element . Function search and return 1 if element is Present in the given list
otherwise return -1 . Using Binary search

Ans-6 –
def search (a,b,c,x):
if c >= b :
mid = (c+b)//2
if a(mid) == x :
return mid
elif a(mid)> x:
return search ( a,b,c-1,x)
else :

return search (a,b+1,c,x)


else :
return -1

Input :-
B

Output :-
1
Q-7 – Write a program in python , to input a string check and display given string is
A palindrome or not.
Ans-7 –

Def palindrome(a):
if (a==a[ : :-1]) :
return “The string is palandrome”
else :
return “ The string is not palandrome “
b= input(“Enter the string”)
print (palandrome (b))

INPUT :-
Cab
Output :-
The string is not a palandrome
Q-8 – Write a program in python, to create a number list. Search and display largest
And smallest number present in a list .Without using built-in function.
Ans-8 –

L=[]
n= int(input(“Enter the number”))
for i in n:
a= in(input(“Enter the elements “))
L.append(a)
print(L)
b= [0]
c=[0]
for j in L :
if j < L:
c= j
print(c,”is smallest”)
elif j > L:
b= j
print(b,”is largest”)

Input :-

Enter the no. 2


Enter the element 1
Enter the element 2

Output :-
1 is the smallest
2 is the largest
Q-9 – Write a program in python, to create a number list. Calculate and display sum Of
those elements whose last digit is 5.
Ans-9 –

L= []
n= int(input(“Enter the
no.”)) for i in n:
a= int(input(“Enter the element “))
L.append(a)
print(L)
s=0
for j in L:
if j % 10 ==5 :
s+= j
print(s)
Input :- Enter no 1. Enter element 5
Output :- 5
Q-10 -
Write a program in python, to create two number lists a and b . Swap and Display all elements
of both lists.

Ans-10 –
a=[]
b=[]

n=int(input(“Enter the no.”))


m=int(input(“Enter the
no.”)) for i in range(n):
c=int(input(“Enter the element
“) a.append(c)
print(a)
for i in range(m):
d=int(input(“Enter the element
“)) b.append(d)
print(d)
a,b=b,a
print(a)
print(b)

Input :-
Enter the no. 1
Enter the element 5
Enter the no. 1
Enter the element 10
Output :-[5],[10],[10],[5]
Q-11 - Write a UDF in python, it will take a list as a function argument . Replace and Display
first half elements with second half elements of a list.
For example: list elements are : 1 2 3 4 5

Output is : 4 5 3 1 2

Ans-11 –
L=[]
n=int(input(“Enter the no.))
for i in range (n):
a=int(input(“Enter the element “))
L.append(a)
print(L)
b=len(L)//2
x=L[ :b]
y=L[b: ]
x.extend(y)
print(x)

Input :-
Enter a no. 2
Enter element 3
Enter element 4

Output :-

[3,4]
[4:3]
Q-12 -Write a function in PYTHON that counts the number of “Me” or “My” words Present in
a text file “DIARY.TXT”. If the “DIARY.TXT” contents are as follows:
My first book was Me and My Family. It gave me chance to be Known to the world. The output
of the function should be:
Count of Me/My in file: 4

Ans-12 –

def count():
f=open(“Dairy.txt”,”r”)
a=f.read()
b=a split()
c=0
d=0
for i in b:
if i == “Me”:
c+= 1
print(c)
elif i ==”My”
d+=1
print(d)
f.close()
count()

Input :-

Output :-
Q-13 -Write a function in PYTHON to read the contents of a text file “Places.Txt” and Display
all those lines on screen which are either starting with ‘P’ or with ‘S’.

Ans-13 –
def read():
f= open(“Places.txt”,”r”)
a=f.read()
for i in a:
if i[0].isupper ==”P” or i[0].isupper==”S”:
print(i)
f.close()
read()

Input :-
Output :-
Q-14 – Write a function EUCount() in PYTHON, which should read each character of a Text
fileIMP.TXT, should count and display the occurrences of alphabets E and U (including
small cases e and u too).

Ans-14 –
def EUcount():
f=open(“IMP.txt” ,
“r”) a=f.read()
b=a split()
c= 0
for i in b:
if i in “uU” or I in “eE”:
c+=1
print(c)
f.close()
EUcount()

Input :-

Output :-
Q-15 – Write a function in PYTHON to search for a BookNo from a binary file
“BOOK.DAT”, assuming the binary file is containing the records of the following Type:
(“BookNo”,
“Book_name”).Assume that BookNo is an integer

Ans-15 –
import pickle as p
def search ():
f= open(“Book.dat”,”rb”)
n=int(input(“Enter the book
no.”)) While True :
try:

rec=p.load(f)
for i in rec:
if i[0]==n:
print(rec)
except:
break
f.close()
search()

Input :-

Enter the book no. 5

Output :-

(“5”,”-”)
Q-16 –Write a function in Python for PushS(List) and for PopS(List) for performing Push and
Pop operations with a stack of List containing integers.
Ans-16-

L=[]
Stack=[]
n=int(input(“Enter the no”))
for i in range(n):
integer=int(input(“Enter some integer”))
L.append(integer)
print(L)
def PushS(L):

for i in L:
if i.isdigit == True:
stack.append(i)
print(stack)
def Pops():
While True:
if stack == []:
print(“stack is empty”)
break
else:
print(stack.pop())
PushS()
PopS()

Input :-
Enter no. 1
Enter some integer 2
Output :-
[2]

[2]
Q-17 – 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-17 –

Import csv
def singlerow():
f=open(“Student.csv”, “w” , new line” “)
wobj = csv.writer(f)
header=[“Sno.” , “Sname” , “Sclass”]
wobj.writerow(header)
f.close()
def multirecord():
f=open(“Student.csv” , “w” , new line=” “)
wobj = csv.writer(f)
L=[]
n=int(input(“Enter the no.”))
for i in range (1,n+1) :
Sno. = int(input(“Enter the student
no.”)) Sname=input(“Enter the
studentname”)) Sclass=input(“Enter the
student class”)) a=[Sno.,Sname,Sclass]
L.append(a)
print(a)
wobj.writerows(L)
f.close()
def display ():
f=open(“Student.csv”, “r”)
robj= csv.reader(f)
a=list(robj)
for i in a:
print(i)
f.close()
While True:
print(“1, for single record”)
print(“2, for multirecord”)
print(“3, for display”)
print(“4, for exit “)
choise = int(input(“Enter your choise”))
if choise == 1:
singlerecord()
elif choise == 2:
multirecord()
elif choise == 3:
display()
elif choise == 4:
break
else :
print(“Incorrect Choise”)

Input :- Enter choise 5Output :- Incorrect choise


Q-18 – Write a menu-driven program to perform all the basic operations using Dictionary on
student binary file such as inserting, reading, updating, Searching and deleting a record .

Ans-18 –
import pickle as p
import os
def inserting ():

f= open (“Student.dat” , “wb”)


Sno.= int(input(“Enter student roll no. “))
Sname= input(“Enter the student name
“) Sclass = input(“Enter the student class
“) a = [Sno.,Sname,Sclass]
p.dump(a,f)
f.close()
def reading():
f= open(“Student.dat”, “rb”)
While True :
try :
rec= p.load(f)
print(rec)
f.close()
def updating():
f= open(“Student.dat” , “wb”)
g=open(“abc.dat” , “rb”)
While True :
try :
rec=p.load(f)
if rec[1]== “ Ankit”:
rec[0]+=2
p.dump(rec,g)
except:
break
f.close()
g.close()
def removing():
f= open(“Student.dat”, “ wb”)
g=open(“abc.dat” , “ rb”)
While True:
try :
rec= p.load(f)
print (rec)
except :
break
p.dump(g)
f.close()
g.close()
os.remove(“Student.dat”)

os.rename(“Student.dat”, “abc.dat”)
While True:
print(“1,for inserting”)
print(“2,for reading”)
print(“3,for updating”)
print(“4,for renaming”)
print(“5,for break”)
choise = int(input(“Enter the choise”))
if choise == 1:
inserting()
elif choise == 2:
reading()
elif choise == 3:
updating ()
elif choise == 4:
renaming()
elif choise == 5:
break
else :
print(“Incorrect choise”)

Input :-

Enter choise 6

Output :-

Incorrect choise
Q-19 -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-19 –
L=[]
Student=[]
n=int(input(“Enter the
no.”)) for i in range(n):
rn=int(input(“Enter the roll.no”))
sn=input(“Enter the student name:”)
a=[rn,sn]
L.append(a)
print(L)
def Push(L):
for i in L:

Student.append(i)
Print(Student)
def Pop():
if Student == []:
print(“Student is empty”)
break
else :
print(student.pop())
def show():
for i in
Student:
Push(L) print(i)
Pop()
Show()

Input :-
Enter the no. 1
Enter the roll no. 13

Enter the student name: Kanav


Output :-
[13, “Kanav”]
13, “Kanav”
“Student is empty”
[13, “Kanav”]
Q-20 – 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) 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-20 –

import mysql.connector as m
def connect():
mydb = m.connect(
host = “local host”
user = “ your username”
password= “your password”
database = “Company database “ )
mycursor= mydb.cursor()
return mycursor
def fetch (mycursor):
sql = “ Select * from emp where salary > 70000”
cursor.execute(sql)
result=cursor.fetchall()
for i in result ():
print(f “ Employee ID : {i[0]} : {i[1]} , salary :{i[2]} ”)
def update(cursor):
sql= “Update emp set salary = salary + 1000 where salary < 80000 “
cursor.execute(sql)
print(“ Salaries of employees earning less than 80000 updated by 10000 “
def delete (cursor):
salary = int(input(“Enter the salary”))
sql= “ Delete from emp where salary = % s”
cursor.execute(sql,(salary,))
print(“Delete record”)
if name == “ _main_” :
mycursor= connect()
print( “ Select
Operation”)
print( “ 1, fetch high salary employees “)
print( “ 2, update low salary employees “)
print( “ 3, Delete by salary “)
choise = int(input(“Enter your choise “))
if choise == 1 :
fetch(mycursor)
elif choise == 2 :
update(mycursor)
elif choise == 3 :
delete(mycursor)
else :
print(“ Invalid Choise “)
mycursor.connection.commit()
mycursor.close()
Input :-
Enter choise 10
Output :- Invalid choise
Q- 21 – Consider the tables EMPLOYEE and SALGRADE given below and answer (a) and
(b)parts of this question.
(a) Write SQL commands for the following statements:

(I) To display the details of all EMPLOYEEs in descending order of DOJ.


(II) To display NAME and DESIG of those EMPLOYEEs whose SALGRADE
is either S02 or S03.
(III) To display the content of the entire EMPLOYEEs table, whose DOJ is
in between ’09-Feb-006’ and ’08-Aug-2009’.
(IV) To add a new row with the following content: 109,‘Harish
Roy’,‘HEAD- IT’,‘S02’,‘9-Sep-2007’,’21-Apr-1983’ (b) Give the output of
the following SQL queries:
(V) SELECT COUNT(SGRADE),SGRADE FROM EMPLOYEE GROUP BY SGRADE;
(VI) SELECT MIN(DOB),MAX(DOJ) FROM EMPLOYEE;
(VII) SELECT SGRADE, SALARY+HRA FROM SALGRADE WHERE SGRADE =’S02’;

Ans- 21 –

(a) (1) Select * from employees order by DOJ desc ;


(2) Select Name, Design from Employees where salgrade in (S02, S03) ;

(3) Select * from Employees whose DOJ between ’04-Feb-2006’ and ’08-Aug-2009’ ;

(4) Alter table Employees add [109 int (3), ‘Harish Roy’ varchar (20) , ‘ Head-it’ varchar (20)
, ‘S02’ char (3) , ‘ 09-Sep-2007’ date , ’08-Aug-2009’ date ;
(b) (1)
Count (S Grade) S Grade
5 S03
S02
S03
S02
S01
(2)

Min (DOB) Max (DOJ)


03-Mar-1984 23-Mar-2003
(3)

S Grade Salary + HPA

S02 44000
Q-22 :- Study the following table and write SQL queries for questions (1) to (4) and output for
(5) And (6).

(1) Write SQL query to display Pname, Quantity and Rate for all the orders that are either
Pencil or Pen.
(2) Write SQL query to display the orders which are not getting any Discount.
(3) Write SQL query to display the Pname,
Quantity and Sale_date for all the orders whose Total cost (Quantity * Rate) is greater than 500.
(4) Write SQL query to display the orders whose Rate is in the range 20 to 100.
(5) SELECT Pname, Quantity from Orders WHERE Pname LIKE(‘_e%’);

(6) SELECT Pname, Quantity, Rate FROM Orders Order BY Quantity DESC;
Ans-22 –
(1) Select Pname, Quantity, Rate from Orders where Pname is either Pen or Pencil ;
(2) Select * from Orders where Discount is Null ;

(3) Select Pname, Quantity, Sale_date from Orders where (Quality*Rate) > 500 ;
(4) Select * from Orders where rate between 2p and 100 ;
(5)

Pname Quantity
Eraser 100

(6)
Pname Quantity Rate

Eraser 100 5

Copy 50 20

Pencil 20 10

Book 10 100

Pen 10 20
Q-23 – Write SQL commands for (i) to (vi) on the basis of relations given below:
(1) To show the books of FIRST PUBL. Publishers written by P. Purohit.

(2) To display cost of all the books published for FIRST PUBL.

(3) Depreciate the price of all books of EPB publishers by 5%.

(4) To display the BOOK_NAME and price of the books, more than 3 copies of which have
Been issued.
(5) To show total cost of books of each type.

(6) show the details of the costliest book.

Ans-23 –

(1) Select Book_name from Books where publisher is first PUBL. and auther name
is P.Purohit ;
(2) Select cost from Books where publisher is first PUBL. ;
(3) Seect price -5% from Books where publisher is EPB;
(4) Select book_name, price from Books where qty > 3 ;
(5) Select (qty , Price) , type from Books ;
(6) Select * from Books where Max(Price) ;
Q-24 – Consider the given table and answer the questions.
(1) To show all information of students where capacity is more than the no. of students in
Order of rtno.

(2) show area_covered for buses covering more than 20 km., but charges less than 80000.

(3) To show transporter-wise total no. of students travelling.


(4) To show rtno, area_covered and average cost per student for all routes where average
cost Per student is—charges/noofstudents.
(5) Add a new record with the following data: (11, “Motibagh”,35,32,10, “kisan tours”, 35000)

(6) Give the output considering the original relation as given:


(a) Select sum(distance) from schoolbus where transporter= “Yadav travels”;
(b) Select min(noofstudents) from schoolbus;
(c) select avg(charges) from schoolbus where transporter= “Anand travels”;
(d) distinct transporter from schoolbus

Ans-24 :-
(1) Select * from school bus where capacity> No. of student order by rtno. ;
(2) Select area covered from school bus where distance > 20 and charges < 80000 ;
(3) Select Sum(No. of student) from school bus group by transporter ;
(4) Select rtno. , area covered, (charges/No. of student) from school bus ;
(5) Alter table school bus add [ 11 int (2) , “Motibagh” varchar (20) , 35 int (3) , 32 int (3)
, 10 int (2) , “Kissan Tours” varchar (30) , 35000 int (7) ]
(6) (a)
Sum(Distance)
180000
(b)

Min(No. of student)

40

(c)

Avg(Charges)

81666

(d)

Distinct(Transporter)

Shivam Travels

You might also like