Computer Science Project
Computer Science Project
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 .
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
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 :-
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 :-
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 :-
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 :
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 :-
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=[]
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 :-
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.
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”)
Ans-18 –
import pickle as p
import os
def inserting ():
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
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:
Ans- 21 –
(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)
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.
(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.
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.
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