East Delhi Public School
East Delhi Public School
CS REPORT FILE
coDE FilE
sEssioN 2022-2023
NaME:-RitEsh KuMaR pal
class:-12th ‘b’
Roll No. :-34
subJEct:-coMputER sciENcE
subMittED to:- MR.s pRiyaNKa MaM
subMittED by:- RitEsh KuMaR pal
Certificate
This is to certify that
RITESH KUMAR PAL of
class XII Springdale has
worked on the project
“SOME CODEING FILE”
to my full satisfaction.
DATE:-
SIGNATURE:-
{MR.s PRIYANKA MAM}
It is a pleasure to acknowledge many
people who knowingly helped me
complete my project. First and
foremost, I would like to express my
regards towards PRIYANKA
MAM the honorable teacher of my
school for her encouragement and
guidance. I would also like to express
my immense gratitude towards ,
cooperation and support extended
during the completion of this project.
Write a python Program to take input for a number, calculate and print its square
and cube?
b=a*a
c=a*a*a
print("Square = ",b)
print("cube = ",c)
Output:
Program:2
Write a python program to take input for 2 numbers, calculate and print their sum,
s=a+b
p=a*b
if(a>b):
d=a-b
else:
d=b-a
print("Sum = ",s)
print("Product = ",p)
print("Difference = ",d)
Output:
Program:3
Write a python program to take input for 3 numbers, check and print the largest
number?
m=a
else:
if(b>c):
m=b
else:
m=c
print("Max no = ",m)
Output:
Method:2
max=num1
elif(num2>num3):
max=num2
else:
max=num3
print("Max no = ",max)
Output:
if(op=="+"):
c=a+b
print("Sum = ",c)
elif(op=="*"):
c=a*b
print("Product = ",c)
elif(op=="-"):
if(a>b):
c=a-b
else:
c=b-a
print("Difference = ",c)
elif(op=="/"):
c=a/b
print("Division = ",c)
else:
print("Invalid operator")
Program: 5 Write a python program to take input for a number and print its table?
i=1
while(i<=10):
table=num*I
i=i+1
Output:
Program:6
Write a python program to take input for a number and print its factorial?
i=1
f=1
while(i<=n):
f=f*i
i=i+1
print("Factorial = ",f)
Output:
Program:7
Write a python program to take input for a number check if the entered number is
Armstrong or not.
n1=n
s=0
while(n>0):
d=n%10
s=s + (d *d * d)
n=int(n/10)
if s==n1:
print("Armstrong Number")
else:
Program:8
Write a python program to take input for a number and print its factorial using
recursion?
def recur_factorial(n):
if n == 1:
return n
else:
return n*recur_factorial(n-1)
num = 7
if num < 0:
print("Sorry, factorial does not exist for negative
numbers")
elif num == 0:
else:
Output:
Program:9
def recur_fibo(n):
if n <= 1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))
else:
print("Fibonacci sequence:")
for i in range(nterms):
print(recur_fibo(i))
Output:
Fibonacci sequence:0112358132134>>>
Program: 10
Write a python program to maintain book details like book code, book title and price
using stacks data structures? (implement push(), pop() and traverse() functions)
"""
push
pop
traverse
"""
book=[]
def push():
bk=(bcode,btitle,price)
book.append(bk)
def pop():
if(book==[]):
else:
bcode,btitle,price=book.pop()
def traverse():
if not (book==[]):
n=len(book)
for i in range(n-1,-1,-1):
print(book[i])
else:
while True:
print("1. Push")
print("2. Pop")
print("3. Traversal")
print("4. Exit")
if(ch==1):
push()
elif(ch==2):
pop()
elif(ch==3):
traverse()
elif(ch==4):
print("End")
break
else:
print("Invalid choice")
Output:
Write a python program to maintain employee details like empno,name and salary
using Queues data structure? (implement insert(), delete() and traverse() functions)
"""
add employee
delete employee
"""
employee=[]
def add_element():
emp=(empno,name,sal)
employee.append(emp)
def del_element():
if(employee==[]):
else:
empno,name,sal=employee.pop(0)
print("poped element is ")
def traverse():
if not (employee==[]):
n=len(employee)
for i in range(0,n):
print(employee[i])
else:
while True:
print("3. Traversal")
print("4. Exit")
if(ch==1):
add_element()
elif(ch==2):
del_element();
elif(ch==3):
traverse()
elif(ch==4):
print("End")
break
else:
print("Invalid choice")
Output:
Program:12
Write a python program to read a file named “article.txt”, count and print total
def count_alpha():
lo=0
with open("article.txt") as f:
while True:
c=f.read(1)
if not c:
break
print(c)
#function calling
count_alpha()
Output:
Program:13
Write a python program to read a file named “article.txt”, count and print the
following:
(ii)total alphabets
def count():
a=0
ua=0
la=0
d=0
sp=0
spl=0
with open("article.txt") as f:
while True:
c=f.read(1)
if not c:
break
print(c)
a=a+1
ua=ua+1
else:
la=la+1
d=d+1
if(c==''):
sp=sp+1
else:
spl=spl+1
# function calling
count()
Output:
Welcome to cbsepython.
>>>
Program: 14
Write a python program to read a file named “article.txt”, count and print total
def count_words():
w=0
with open("article.txt") as f:
for line in f:
print(word)
w=w+1
# function calling
count_words()
Output:
Amit
Ankur
and
Ajay
>>>>
Program: 15
Write a python program to read a file named “article.txt”, count and print total
filepath = 'article.txt'
vowels="AEIOUaeiou"
cnt = 1
while line:
if(line[0] in vowels):
#print(line)
cnt=cnt+1
line = fp.readline()
Output:
Program:16
def insert_data():
#take input for the details and then save the record in
the databse
import mysql.connector
db =
mysql.connector.connect(host="localhost",user="root",
password="admin")
c = db.cursor()
try:
db.commit()
print("Record saved")
except:
db.rollback()
db.close()
# function calling
insert_data()
Output:
Program 17:
def display_all():
import mysql.connector
db =
mysql.connector.connect(host='localhost',user='root',
passwd='admin',database='test4')
try:
c = db.cursor()
c.execute(sql)
countrow=c.execute(sql)
data=c.fetchall()
print("=========================")
print("=========================")
r=eachrow[0]
n=eachrow[1]
p=eachrow[2]
print("=========================")
except:
db.rollback()
db.close()
# function calling
display_all()
Output:
Program :18
def search_roll():
import mysql.connector
db =
mysql.connector.connect(host="localhost",user="root",
passwd="admin",database="test")
try:
z=0
c = db.cursor()
c.execute(sql)
countrow=c.execute(sql)
data=c.fetchall()
r=eachrow[0]
n=eachrow[1]
p=eachrow[2]
if(r==roll):
z=1
print(r,n,p)
if(z==0):
except:
db.rollback()
db.close()
# function calling
search_roll()
Output: