0 ratings 0% found this document useful (0 votes) 114 views 32 pages Class 12 Cs Project
The document is a project certificate for Hrituraj Singh Chandel of class XII, certifying the completion of a computer science project under the guidance of Ms. Stuti Dixit for the academic year 2024-2025. It includes an index of various programming tasks and examples related to Python, file handling, and database operations. The document also expresses gratitude to teachers, parents, and peers for their support during the project.
AI-enhanced title and description
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here .
Available Formats
Download as PDF or read online on Scribd
Go to previous items Go to next items
Save class 12 cs project For Later
220 D, Defence colony, Jajmau , Kanpur 208010
Name:
Class:
Roll No:
Subject :
Subject Code:
: og
5 f
em he oye
mS
ss Las
ba Submitted to Submitted by
S04Certificate
YZ
Ye This is to certify that Hrituraj
singh chandel of class XII has
successfully completed his
computer science project
Practical file under the
guidance of Ms Stuti Dixit
Mam for the academic year
2024-2025 as per guidance
issued by CENTRAL BOARD
OF SECONDARY
EDUCATION (CBSE)
Internal Examiner
\
Principal
External examinerI would like to express my special
thanks of gratitude to my subject
teacher Ms Stuti Dixit Mam and our
school SARASWATI VIDYA
MANDIR INTER COLLEGE
Principal Mrs Komal Chandiok
Sharma Who gave me the
opportunity to make this practical
file and helped me in completing my
project
I am deeply grateful to my parents
friends and classmates who
encouraged me in finishing and \
finalizing the practical file on time It N
was a great learning experience for =
me >INDEX
aa Page | Sign
S.No. Prog No.
1. | Program to enter two numbers and print the arithmetic
operations like +,-;*/y// and %
2 | Write a program to find whether an inputted number is
perfect or not
3. | Write a Program to check of the entered number
Armstrong or not.
4. | Write a Program to find the factorial of the entered number.
5. | Write a program to enter the number of terms and to print
the Fibonacci Series.
6. | Write a program to enter the string and to check if it's
indrome or not using loop.
7._| Recursively find the factorial of a natural number.
8. _| Program to Read a file line by line and print it.
9. | Remove all the lines that contain the character “a” in a file
and write it into another file,
10. | Read a text file and display the number of
vowels/consonants/up percase/lowercase characters in the file.
11. | Create a binary file with name and roll no. Search for a given
roll number and display the name, if not found display
appropriate message.
12. | Write a program to perform read operation on a CSV file
(Student.csv)
13. ] Create a CSV file(Student.csv), and perform write operation
on the CSV, to enter details of students including (R.No,
Name, Percentage)
14. | Write a random number generator that generates random
numbers between 1 and 6 (simulates a dice)
15. | Write a python program to implement a stack using a list
data structure.
16. | Write « menu-driven python program to implement stack
operation.
17. | Write a program to implement a stack for the employee
details (empno, name)
18. | Write a python program to check whether a string is a
palindrome or not using stack.
19. | Queries Set 1 (Database Fetching records )
20. | Queries Set 2(Based on Functions)
21. | Queries Set 3 (DDL Commands)
22. | Queries Set 4(Based on Two Tables)
23. | Queries Set 5 (Group by, Order By)
2
Write a MySQL connectivity program in Python to
* Create a database school
* Create a table students with the specifications-
ROLLNO integer, STNAME character(10) in MySQL
and perform the following operations:
© Insert two records in it.
© Display the contents of the table.© € 6&6 €@ €
F
i”
'
é
eseecerctrtroret eo eer e epee
»4
Perform all the operations with reference to table ‘students*
through MySQL - Python connectivity.PROGRAM 1
rot rt mbers and print thi
operations like +,-,*,/,//and %.
print ("Enter any two positive integer numbers: ")
P, q = int(input()), int(input())
sum, sub, mul, div, floor_div, mod = 0, 0, 0, 0, 0, 0
un = ptq
sub =p-q
ml =p*q
div=p/q
floor_div = p//q
mod =p %q
print("\n")
print ("SUM ") Pr" 4+", q, "=", sum)
print ("DIFFERENCE ", p, " ", sub)
print ("PRODUCT "; Pp," “, mul)
print ("QUOTIENT ", Py ™ ", div)
print("Floor division", p, "// ", q, "=", floor_div)
print ("MODULUS oe ee =", mod)
Output :
Enter any two positive integer numbers:
14
2
SUM 14 + 2
DIFFERENCE 14 - 2
PRODUCT 14 * 2
QUOTIENT 14 / 2
Floor division 14 / 7
MODULUS 14 % 2PROGRAM 2
or not.
n = int(input("Enter any number: "))
suml = 0
for i in range(1,n):
if(n $i == 0):
suml =suml + i
if (suml == n):
print("The number is a perfect number")
else:
print("The number is not a perfect number")
Output:
Enter any number: 6
The number is a perfect number
Enter any number: 5
The number is not a periect numberProgram 3
Writ
not.
no=int(input("Enter any number to check : "))
= no
=0
while (no>0) :
ans = no % 10
sum sum + (ans * ans * ans)
no = int (no / 10)
if sum == nol:
print ("Armstrong Number")
else:
print("Not an Armstrong Number")
Output :
Enter any number to check : 371
Armstrong Number
Enter any number to check : 124
Not an Armstrong NumberPROGRAM 4
Write a program to find factorial of the entered number.
hum = int(input("Enter the number for calculating its factorial : "))
fact = 1
ie
while ic=num:
fact = fact#i
isita
print ("The factorial of ",num,
Output :
Enter the number for calculating its factorial
The factorial of 5 = 120
Enter the number for calculating its factorial : 14
The factorial of 14 = 87178291200PROGRAM 5
Write a program to enter the number of terms and to print the
Fibonacci series.
=int (input ("Enter the limit: "))
i
x=0
ye.
ze
print ("Fibonacci series \n")
print (x, y,end= " ")
while(z<= i):
print(z, end=" ")
x=y
yrz
z=xty
Output :
Enter the limit: 14
Fibonacci series
0112PROGRAM 6
Write a program to enter the strin k if it’s
alindrome or not usin
ispalindrome(s) :
return s s{:: -1]
str(input("Enter the string data: "))
ans = ispalindrome(s)
if ans:
print("It is a Palindrome string")
else:
print("It is not a Palindrome string")
Output :
Enter the string data: level
It is a Palindrome string
Enter the string data: vijay
It is not a Palindrome stringPROGRAM 7
ecursiv factorial of
def recur_factorial (n):
ifn Sei:
return n
else:
return n#recur_factorial (n-1)
num = int (input ("Enter Integer value: "))
# Check if the number is negative
if mum < 0:
print("Sorry, factorial data does not exist for negative numbers")
elif num = 0:
print("The factorial of 0 is 1")
else:
print ("The factorial of",num,"is",recur_factorial (num) )
Output :
Enter Integer value: 14
The factorial of 14 is 87178291200PROGRAM 8
line and print it.
cas
a nod
WELCOME To
CALC Tey
filel = open('myfile.txt','r')
Lines = filel.readlines()
count = 1
# Strips the newline character
for line in Lines:
print ("Line{}: {}" - format (count, line.strip()))
count +=count
Output :
Linel: WELCOME TO
Line2: PYTHON WORLDPROGRAM 10
Read a text file and display the number of
vowels/consonants/uppercase/lowercase characters in the file,
=
nd
pate aa)
Cerro)
filel
vowels
consonants = 0
lowercase = 0
uppercase = 0
strl = filel.read()
for i in strl:
if (>= "a" and ice 2"):
lowercase
elif (i>= "A" an
uppercase +=1
strl:
lower ()
(j = "a" or j =
vowels +21
if j-isalpha():
consonants +=1
print ("lower case count‘, lowercase)
print (upper case count:", uppercase)
print ("vowels count:", vowels)
print ( yants count: ", consonants)
Output :
lower case count: 0
upper case count: 20
vowels count: 6
consonants count: 14Program 11
Create a binary file with name and roll no. Search for a given roll
Number and display the name, if not found display appropriate
mi e.
import pickle
def Writerecord(sroll,sname) :
with open (‘StudentRecordl.dat','ab') as Myfile:
srecord=("SROLL" :srol1,"SNAME" : name)
pickle. dump (srecord,Myfile)
def Readrecord() :
with open ('StudentRecordl.dat','rb') as Myfil
print ("\n-------DISPALY STUDENTS DETAILS-
print("\nRoll No.",' ','Name','\t',end='')
print ()
while Tr
rec=pickle. load (Myfile)
print(' ‘,rec['SROLL'],'\t ' ,rec['SNAME'])
EOFError:
Input () :
nt (input ("How many records you want to create
for etr in range(n):
sroll=int (input ("Enter Roll No: "))
sname=input ("Enter Name: ")
Writerecord(sroll,sname)Your Choices are:
1.Insert Records
2.Dispaly Records
3.Search Records (By Roll No)
0.Exit (Enter 0 to exit)
Enter Your Choice: 1
How many records you want to create :2
Enter Roll No: 01
Enter Name: Rohan
Enter Roll No: 02
Enter Name: Ram
Your Choices are:
1.Insert Records
2.Dispaly Records
3.Search Records (By Roll No)
0.Exit (Enter 0 to exit)
Enter Your Choice: 2Ram
Your Choices are:
1.Insert Records
2.Dispaly Records
3.Search Records (By Roll No)
O.Exit (Enter 0 to exit)
Enter Your Choice: 3
Enter a Rollno to be Search: 02
Roll NO: 2
Name: Ram
Record not find
Try Again
Your Choices are:
1.Insert Records
2.Dispaly Records
3.Search Records (By Roll No)
0.Exit (Enter 0 to exit)
Enter Your Choice:PROGRAM 12
Write a program to perform read operation on a CSV file
Output:
(student.csv).
import csv
f = open('student.csv','r')
cw = csv.reader(f)
for k in cw:
print (k)
£.close()
['i»gName', 'Percentage']
['Rohan',
'B9']
('Raj', '74']
('Krish',
'90']PROGRAM 13
Create a CSV file (student.csv) and perform write operation on
the CSV, to enter details of student Including (Roll no., Name,
Pers A
import csv
with open('Student_Details.csv','w',newline='') as f:
writecsv=csv.writer (f,delimiter=',')
choice='y'
while choice.lower()="y':
rl=int (input ("Enter Roll No.: "))
nput ("Enter Name: ")
p=float (input ("Enter Percentage: "))
writecsv.writerow({rl,n,p])
print(" Data saved in Student Details file..")
choice=input ("Want add more record(y/n).....")
open('Student_Details.csv','r',newline='') as fileobject:
readcsv=csv. reader (fileobject)
for i in readesv:
print (i)
Output:
Enter Roll No.: 14
Enter Name: Hriday
Enter Percentage: 94
Data saved in Student Details file..
Want add more record(y/n).....n
['14', 'Hriday', '94.0']PROGRAM 14
Write a random number generator that rates random
numbers between 1 and 6 (simulates a dice).
import random
a =[]
for i in range(7):
a.append (random. randint (1,6) )
print ("Randomised list is",a)
Output :
Randomised list is [5, 3, 4, 2, 5, 6, 5]PROGRAM 15
Write a python pr to I nt a sti fis
structure.
def isempty (stk):
if stk==[]:
return True
else:
return False
push (stk, item) :
stk. append (item)
top=len (stk) -1
pop (stk) :
if isempty (stk):
return "underflow"
else:
item=stk.pop()
if len(stk)==0:
top=None
else:
top=len (stk) -1
return item
def peek (stk) :
if isempty (stk) :
return "underflow"
else:
top=len (stk) -1
return stk[top]def display (stk) :
if isempty (stk):
print('stack is empty')
else:
top=len (stk) -1
print (stk[top] ,'<-top')
for i in range(top-1,-1,-1):
print (stk[i])#Driver Code
def main():
stk=[]
top=None
while True:
print ('''stack operation
1.push
2.pop
3.peek
4.display
5.exit''')
choice=int (input('enter choice:'))
if choice==1:
item=int (input ('enter item:'))
push (stk, item)
elif choice==2:
item=pop (stk)
if item=="underflow":
print('stack is underflow')
else:
print ('poped')
elif choice==3:
item=peek (stk)
if item=="underflow":
print('stack is underflow’)
else:
print('top most item is:',item)
elif choice==4:
display (stk)
elif choice==5:
break
else:
print ('invalid')
exit()Output :
stack operation
1.push
2.pop
3.peek
4.display
5.exit
choice:1
item:14
operation
choice:1
item:2
operation
1.push
2.pop
3.peek
4.display
5.exitenter choice:2
Ppoped
stack operation
enter choice:4
14 <-top
stack operationdef
def
def
def
Push (stk,e)
stk. append (e)
top = len(stk)-1
display (stk!
if check_stack_isEmpty (stk) :
print ("Stack is Empty")
else:
top = len(stk) -1
print (stk[top] ,"~Top")
for i in range(top-1,-1,-1):
print (stk(i])
Pop_stack (stk):
if check_stack_isEmpty (stk) :
return "UnderFlow”
else:
e = stk.pop()
if len(stk) ==
top = None
else:
top = len(stk)-1
return e
peek (stk) :
if check_stack_isEmpty (stk) :
peek (stk) :
if check_stack_isEmpty (stk) :
return "UnderFlow"
els
top = len(stk)-1
return stk[top]Output :
main_menu()
Stack Implementation
1 - Push
- Pop
- Peek
- Display
- Exit
Enter the your choice:1
Enter the value to push an element:14
Stack Implementation
1 - Push
2 - Pop
3 Peek
4 - Display
5 Exit
Enter the your choice:1
Enter the value to push an element:2
Stack Implementation
1 - Push
- Pop
Peek
Display
Exit
Enter the your choice:4
2 -Top
14
Stack Implementation
1 - Push
Pop
Peek
Display
Exit
Enter the your choice:5Program 17
im to implement a sti ils (empno, name),
stk=[]
top=-1
def line():
print ('~'*100)
def isempty():
global stk
if stk==(]:
print ("Stack is empty!!!")
else:
None
def push():
global stk
global top
empno=int (input ("Enter the employee number to push:"))
ename-input ("Enter the employee name to push:")
stk. append ([empno, ename])
top=len (stk) -1
def display(i:
glcbal stk
global top
if tops=-
seFmpty (]
else:
top=len(stk)-1
print (stk [top] ,"<-top")
for i in range(top-1,-1,-1):
print (stklil)
def pop_ele():
global stk
global top
if tope=-1:
isEmpty ()
else:
stk.pop()
topstop-1
def main():
while True:
line()stk=[]
top=-1
def line():
print ('~'*100)
def isempty():
global stk
if stk==[]:
print ("Stack is empty!!
else:
None
print ("1. Push")
print("2. Pop")
print (" Display")
print ("4. Exit")
ch=int (input ("Enter your choice:"))
if ch inm
push()
print ("Element Pushed")
elif ch==2:
pop_ele()
elif c :
display()
elif ch==4:
break
else
print ("Invalid Choice")
Output:
3. bieplay
Rover your chotca:t
Inter the employee suaber to push:23
Estar the employee ane to pushiiinesh
Elanant Pushed
pares
2. rep
3. bieplay
rans
Enter your chotce:3
(23, ‘uisash") <-top
HPROGRAM 18
Write a python program to check whether a string Isa
palindrome or not using stack.
# push function
def push (ele):
global top
top t= 1
stack[top] = ele
# pop function
def pop():
global top
ele = stack(top]
top -= 1
return ele
# Function that returns 1 if string is a palindrome
def isPalindrome (string) :
global stack
length = len(string)
# Allocating the memory for the stack
stack = ['0'] * (length + 1)
# Finding the mid
mid = length // 2
i=o
while i < mid:push (string(i})
it=1
# Checking if the length of the string is odd then
neglect the middle character
if length ¢ 2 != 0;
Lte1
# While not the end of the string
while i < length:
ele = pop()
# If the characters differ then the given string
is not a palindrome
if ele != stringlil:
return False
ite
return True
string = input("Enter string to check:*)
if isPalindrome(string) :
print("Yes, the string is a palindrome")
print("No, the string is not a palindrome")
Output:
>>>.
RESTART: 2: /Python Programs
lester string to check:nitin
Yes, the string is a palindrone
>>
RUSTART: B:/Python Prograns/stack.py <_—__—___
enter string to check:Sanjay
the string is not a palindronedef SearchRecord(rol1) :
with open ('StudentRecordl.dat','rb') as Myfil
while True:
try:
rec=pickle. load (Myfile)
if rec['SROLL']==roll:
print("Roll NO:",rec['SROLL'])
print ("Name:",rec['SNAME'])
except EOFError:
print ("Record not find.
print("Try Again.......
break
def main():
while True:
print('\nYour Choices are: ')
print('l.Insert Records')
Print ('2.Dispaly Records')
print('3.Search Records (By Roll No) ')
print('0.Exit (Enter 0 to exit)')
ch=int (input (’Enter Your Choice: '))
if ch==1:
Input ()
elif ch==2:
Readrecord()
elif. ch==
rsint (input ("Enter a Roll no to be Search: "))
SearchRecord (r)
else:
break