ACKNOWLEDGEMENT
I would like to express my special thanks of gratitude to
my Computer Teacher “Mr. Rajesh Mewada” for his able
gratitude and support in completing my Computer
Programs file.
I would also like to extend my thanks of gratitude to my
Principal “Rev. Fr. Melvin C.J.” for providing me with all
the facility that was required.
Name : Sumit parmar
Class : 12th “PCB”
Roll Number:
Certificate
This is to certify that “Sumit parmar” of class XII “PCB”
has successfully completed his Computer Science project
file of “Python Programs” under the guidance of “Mr.
Rajesh Mewada Sir” during the academic session 2025-
2026 as per the guidelines issued by CBSE.
________________________
___________________________
Teacher’s Signature. Principal Signature
__________________________________
External’s Signature
Q.1 Write a python script to calculate simple interest through a function.
ANSWER:
def si(p,time=2,rate=0.10):
return p*time*rate
p = float(input('Enter Principle Amount :'))
x = si(p)
print('Si with default rate and time :',x)
r = float(input('Enter rate of interest :'))
t = float(input('Enter time period :'))
y = si(p,t,r)
print('Si with modified rate and time :',y)
Output :
Q.2 Write a python script to swap two numbers using function.
ANSWER :
def switch(a,b):
a,b=b,a
return a,b
a = int(input('Enter a number :'))
b = int(input('Enter a number :'))
print('Before swapping :')
print('Number1 :',a)
print('Number2 :',b)
print('After Swapping :')
a,b = switch(a,b)
print('Number1 :',a)
print('Number2 :',b)
Output :
Q3. Write a python script to create a module temperature conversion that
stores functions for various temperature conversion e.g,
Fahrenheit to celsius
Celsius to fahrenheit
ANSWER:
def convert(temp):
print('[Link] to celsius')
print('[Link] to fahrenheit')
choose=int(input("Enter your choice:"))
if choose == 1:
print("convert from fahrenheit to celsius :",(temp-32)*5/9,"C")
elif choose == 2:
print("convert from celsius to fahrenheit :",(temp*9/5)+32,"F")
else:
print("please review your input choice,")
temp=float(input("Enter the temperature that to be converted:"))
convert(temp)
Output:
Q4. Write a python script to read a text file line by line and display each word
separated by ‘#’ sign
ANSWER:
File = open("OUTPUT","r")
content=[Link]()
for line in content:
words=[Link]()
for words in words:
print(word+"#",end=")
print("")
Output:
[Link] a Program in python to accept student id, name and country from the
user and store it into external CSV file
ANSWER:
import csv
with open("[Link]","a+")as cs:
csv_writer=[Link](cs)
ans='y'
while ans == 'y' or ans == 'Y':
S_id=input("enter student id:")
name=input("enter student name:")
country=input("enter student country:")
csv_writer=[Link]([S_id,name,country])
ans=input("Do you want to input more details(y/n):")
[Link]=(0)
[Link]=[Link](cs)
for line in csv_reader:
print(line)
[Link]()
Output:
Q6. Write a python script to a binary file with the name and roll number to
search on a
given roll number and display for our name if not found display appropriate
message
ANSWER:
import pickle
x=open("student_data.dat","w+b")
n=int(input("Enter number of student:"))
details=[]
for i in range(0,n):
roll=int(input("Enter roll no .: "))
name=input("Enter Name:")
cl=int(input("Enter class:"))
[Link]([roll,name,cl])
[Link](details,x)
[Link](0)
y=[Link](x)
flag=0
roll=int(input("Enter roll no. to be search for student data:"))
for i in y:
if roll == i[0]:
flag=1
print("Roll NO. Name class")
print(i)
if flag == o:
print("record not found")
[Link]()
Output:
[Link] a Python script to create a binary file with roll number name and marks
input a
roll number and update the mark
ANSWER:
# Create a binary file with name, rollno and marks.
#Input a roll no and update the marks.
f=open('s1','w+b')
n=int(input('Enter number of students:'))
for i in range(n):
name=input('Enter name of student:')
rollno=input('Enter rollno:')
marks=input('Enter marks:')
bname=bytes(name,encoding='utf-8')
brollno=bytes(rollno,encoding='utf-8')
bmarks=bytes(marks,encoding='utf-8')
[Link](brollno)
[Link](bname)
[Link](bmarks)
[Link](b'\n')
[Link](0)
data=[Link]()
[Link](0)
sk=input('Enter the roll no whose marks need updatation :')
bsk=bytes(sk,encoding='utf-8')
I=len(bsk)
loc=[Link](bsk)
if loc<0:
print('Details not present')
else:
[Link](loc+l,0)
i=0
while [Link](1).isalpha():
i=i+1
[Link](-1,1)
marksu=input('Enter updated marks:')
bmarksu=bytes(marksu,encoding='utf-8')
[Link](bmarksu)
print("Entire content of file after updation is :")
[Link](0)
udata=[Link]()
print([Link]())
Output:
Q8. Write a python script for creating a file with some names separated by new
line
character without using write function
ANSWER:
x=open("[Link]","w")
a=[]
for i in range(0,2):
name=input("enter student name:")
[Link](name+'\n')
[Link](a)
[Link]
Output:
Q9. Write a program to implement STACK operations.
ANSWER:
QSTACK IMPLEMENTATIOIN
def isEmpty(stk):
if stk == []:
return True
else:
return False
def Push(stk,item):
stk append(item)
top=len(stk)-1
def pop(stk):
if isEmpty(stk):
return "Underflow"
else:
item=[Link]()
if len(stk) == 0:
top=None
else:
top=len(stk)-1
return item
def Peek(stk):
if is Empty(stk):
return "Underflow"
else:
top=len(stk)-1
return stk[top]
def Display(stk):
if isEmpty(stk):
print("Stack empty")
else:
top=len(stk)-1
print(stk[top]," <- top")
for a in range(top-1,-1,-1):
print(stk[a])
#___main___#
Stack=[]
top=None
while True:
print("STACK OPERATIONS")
print("[Link]")
print("[Link]")
print("[Link] stack")
print("[Link]")
ch=int(input("Enter your choice (1-5):"))
if ch == 1:
item=int(input("Enter item:"))
Push(Stack,item)
elif ch == 2:
item=Pop(Stack)
if item == "Underflow":
print("Underflow! Stack is empty!")
else:
print("Popped item is",item)
elif ch == 3:
item=Peek(Stack)
if item == "Underflow":
print("Underflow! Stack is empty!")
else:
print("Topmost item is",item)
elif ch == 4:
Display(Stack)
elif ch == 5:
break
else:
print("Invalid choice!")
Output:
Q10. Write a program to implement a stack for this book details (book number,
book name). that is now each item node of the stake contains two type of
information - a book number and its name just implement push and display
operations
Answer:
“””Stack:implemented as a list
top:integer having position of topmost element in stack”””
def cls():
print("\n"*100)
def isEmpty(stk):
if stk == []:
return true
else:
return false
def Push(stk,item):
[Link](item)
top=len(stk)-1
def display(stk):
if isEmpty(stk):
print("Stack empty")
else:
top=len(stk)-1
print(stk[top]," <- top")
for a in range(top-1,-1,-1):
print(stk[a])
#_ main_
stack=[]
top=None
while True:
cls()
print("STACK OPERATRIONS")
print("[Link]")
print("[Link] stack")
print("[Link]")
ch=int(input("Enter your choice(1-5):"))
if ch == 1:
bno=int(input("Enter Book [Link] be inserted:"))
bname=input("Enter Book name to be inserted:")
item=[bno,bname] #CREATING A LIST FROM THE INPUT ITEMS.
Push(stk,item):
input()
elif ch == 2:
display(Stack)
input()
elif ch == 3:
break
else:
print("Invalid choice!")
input()
Output:
Q.11 With Reference to the table below, answer the questions that follow:
Write the SQL commands for the following using above tables:
(i) To show firstname, lastname, address and city of all employees living in Pairs.
(ii) To display the content of Employees table in descending order of Firstname.
(iii) To display the firstname, lastname and total salary of all managers from the
tables Employes and Emp Salary, where total salary is calculated as Salary +
Benefits.
(iv) To display the maximum salary among managers and clerks from the table
EmpSalary.
Give the Output of following SQL commands:
i) Select firstname, Salary from Employees, Empsalary where Designation =
'Salesman' and Employees. Empid = [Link];
(ii) Select count(distinct designation) from EmpSalary:
(iii) Select designation, sum(salary) from EmpSalary group by designation having
count(*)>2;
(iv) Select sum(Benefits) from EmpSalary where Designation = 'Clerk';
Answers :
1.
(i)Select firstname, lastname, address, city from Employee where city = "Paris";
(ii)Select * from Employee order by Firstname desc;
(iii)Select firstname, lastname, (Salary + Benefits) "total salary" from Employee
natural join EmpSalary ;
(iv)Select max(Salary) from EmpSalary where Designation in ("Manager",
"Clerk");
2.
2.
v.71666.67
Q12. Write a program in python to extract the first and rows from the relationing
fetch many functions.
Answer:
import [Link] as ms
x=[Link](host='local host',user='root',passwd='root',database='school')
if x.is_connected():
cur=[Link]()
[Link]('select*from school')
data=[Link]()
print(data)
data=[Link]()
print(data)
[Link]()
Output:
Q13. Write a python program insert, update and delete from python through
crude operation
Answer:
import [Link] as ms
x=[Link](host='local host',user='root',passwd='root',database='test_CRUD')
if x.is_connected():
cur=[Link]()
ans='y'
while ans == 'y' or ans == 'y':
choice=int(input("CRUD operations\[Link] data\[Link] [Link]
[Link] data"))
if choice == 1:
more='y'
while more == 'y' or more == 'y':
eid= int(input("enter employee id:"))
ename=input("enter employee name:")
[Link]("insert into emp values({},'{}')".format(eid,ename))
[Link]()
more=input("Do you want to insert more data?(y\n)")
if choice == 2:
[Link]("select*from emp")
data=[Link]()
for i in data:
print(i)
if choice == 3:
update_ch = input("what do you want to update?\[Link]
id\[Link] name")
if upfate_ch == 'A' or update_ch == 'a':
old_eid=int(input("enter existing employee id:"))
new_eid=int(input("enter new employee id:"))
[Link]("update emp set E id={} where
E_id={)".format(new_eid,old_eid))
[Link]()
print("data successfully updated")
if choice == 4:
delete_ch=input("press\[Link] entire [Link] selected data")
if delete_ch == 'A' or delete_ch == 'a':
[Link]("delete from emp")
[Link]()
print("enter data deleted")
if delete_ch == 'B'or delete_ch == 'b':
eid=int(input("enter employee id record to be deleted"))
[Link]("delete from emp where E_id={}.format(eid)")
[Link]()
print("data deleted successfully")
ans= input("run again(y\n)")
[Link]()
Output:
[Link] Program to search for a specific employee information based on
employee ID
ANSWER:
n = int(input('Enter the number of employee: '))
employees = {}
for i in range(n):
name = input('Enter the name of the employee: ')
emp_id = input("Enter employee Id: ")
sal = int(input("Enter the employee salary: "))
address = input('Enter the employee address: ')
employees[name] = [emp_id, sal, address]
while True:
name = input('Enter employee name: ')
info = [Link](name, -1)
if info == -1:
print('Employee does not exist')
else:
print(f'Employee details are: \n Employee Id: {info[0])\n Salary:
{info[1]]\n
Address: info[2])')
exit_choice = input('Do you want to exit [Yes|No]:')
if exit_choice == 'Yes' or exit_choice == 'yes':
break
Output:
Q15 Write a program in python to display the entire data from the EMP table
and display it using tabulate function().
ANSWER:
from tabulate import tabulate
x=[Link](host='local host',user='root',passwd='root',database='School')
if x.is_connected():