0% found this document useful (0 votes)
17 views

Computer Practical

Uploaded by

karla060308
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Computer Practical

Uploaded by

karla060308
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

REPORT FILE

2024-2025

NAME:- KARTIK
CLASS:- XII-A
School:-The Millennium School,
Ayodhya Road, Barabanki.
INDEX
Sl.no Program
Question1 Write a menu driven program to perform mathematical calculations like
Addition, Subtraction, Division, Multiplication between two integers. The
program should continue running until user gives the choice to quit.

Question2 Write a function to compute the factorial of n

Question3 Write a program to print following pattern:


*
***
*****
*******

Question4 A computerized ticket counter of an underground metro rail station charges


for each ride at the following rates:

AGE(in years) AMOUNT per HEAD


18 or above 50 rupees
5 or above but below 18 20 rupees
Accompanying kids below 5 NIL

Write a program which takes the number of people of various age groups
as input and prints a ticket. At the end of the journey, the program states
the number of passengers of different age groups who travelled and the
total amount received as collection of fares.

Question5 Write a program that defines a function ModifyList(L) which receives a list
of integers , updates all those elements which have 5 as the last digit with
1 and rest by 0.

Question6 Write a program that defines a function MinMax(T) which receives a tuple
of integers and returns the maximum and minimum value stored in tuple.

Question7 Write a program with function INDEX_LIST(L), where L is the list of


elements passed as argument to the function. The function returns
another list named ‘indexlist’ that stores the indices of all Non-Zero
elements of L. For e.g. if L contains [12,4,0,11,0,56] then after execution
indexlist will have[0,1,3,5]
Question8 Write a menu driven program with user defined functions to create a text
file MyFile.txt, where choices are:
1-Create text file
2- Generate a frequency list of all the words resent in it
3-Print the line having maximum number of words.
4-Quit
Question9 Write a program to remove all the lines that contains character ‘a’ in a file
and write them to another file.

Question10 Write a program to create a menu driven program using user defined
functions to manage details of Applicants in a binary file APPLICANTS.DAT .
Applicant details include(AppID,AName,Qualification) The available choices
are:
1-Create File
2-Add Applicant
3-Search Applicant on the basis of AppID
4-Modify Applicant
5-Quit

Question11 Write a program to create a menu driven program using user defined
functions to manage Telephone contacts of your friends in a CSV file
MyFriend.csv. (Contact details includes Name,Telephone Contact
No.,EmailID,Address)The available choices are:
1-Create File
2-Add Friend
3-Search Friend
4-Quit
Question12 Write definition of a user defined function PUSHNV(N) which
receives a list of strings in the parameter N and pushes all strings
which have no vowels present in it , into a list named NoVowel.
Write a program to input 10 words and push them on to a list ALL.

The program then use the function PUSHNV() to create a stack of


words in the list NoVowel so that it stores only those words which
do not have any vowel present in it, from the list ALL. Thereafter
pop each word from the list NoVowel and display all popped
words. When the stack is empty display the message “Empty
Stack”.
Question13 Q13 Write a program in Python using a user defined function
Push(SItem) where SItem is a dictionary containing the details of
stationary items {Sname:Price}. The function should push the
names of those items in the stack who have price greater than 75,
also display the count of elements pushed onto the stack.

Question14 Create a table named as CLUB in database GAMES with


appropriate data type using SQL command of following structure
and constraints:
CoachID Primary Key, CoachName Not Null, Age Not Null,
Sports, DateOfApp,
Pay ,Sex.

Question15 Sql query for inserting values in the table named club
Question16 Write sql staementd for the following based in the table club.
Question17 . Create following tables in database MYORG with appropriate
data type using SQL commands of following structure.
Table : Company Table Customer
CID Primary key CustId Primary Key
Name Not Null Name Not Null
City Not Null Price Not Null
Product Name Not Null Qty Check greater
than 0
CID Foreign Key
Question18 Write SQL commands to insert following data in above created
tables Company and Customer , also list all data .
Question19 Write sql commands for the following queries based on tables
company and customer
Question20 Write a pythom interface program using mysql to insert rows in
table club in database games
Question21 Write Python interface program using MySQL to increase price
by 10% in table CUSTOMER of MYORG database
Question22 Write a Python interface program using MySQL to delete all those
customers whose name contains Kumar from table CUSTOMER in
database MYORG.
CERTIFICATE

THIS IS CERTIFIED TO BE THE BONAFIED WORK OF THE


STUDENT IN THE COMPUTER LABORATORY DURING
COMPUTER PRACTICALS FOR THE SSCE AS PRESCRIBED
BY CBSE IN THE YEAR 2024-25.

…………………… ……………………
INTERNAL EXAMINER EXTERNAL EXAMINER
HARDWARE AND SOFTWARE
DETAILS

PC SPECS
CORE I3 10400F
GT 610 GPU
4 GB RAM

SOFTWARE
WINDOWS 10
PYTHON 3.9
PYTHON IDLE
PROGRAM NO. 1 :
SOURCE CODE :

def addition(num1, num2):


return num1 + num2
def subtraction(num1, num2):
return num1 - num2
def division(num1, num2):
if num2 != 0:
return num1 / num2
else:
print("Error: Cannot divide by zero")
def multiplication(num1, num2):
return num1 * num2
while True:
print("Menu:")
print("1 - Addition")
print("2 - Subtraction")
print("3 - Division")
print("4 - Multiplication")
print("5 - Quit")
choice = int(input("Enter your choice: "))
if choice == 1:
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
result = addition(num1, num2)
print("Result:", result)
elif choice == 2:
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
result = subtraction(num1, num2)
print("Result:", result)
elif choice == 3:
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
result = division(num1, num2)
if result is not None:
print("Result:", result)
elif choice == 4:
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
result = multiplication(num1, num2)
print("Result:", result)
elif choice == 5:
print("Exiting the program...")
break
else:
print("Invalid choice! Please choose a number from the menu.")
OUTPUT:
PROGRAM NO. 2:
SOURCE CODE:

def factorial(n): # Function to compute the factorial of n


fact=1
for i in range(1,n+1):
fact*=1
return fact

# code to compute the sum of the series


def main():
sum=1.0
x=int(input("enter the value for x = "))
n=int(input("enter the no of terms = "))
for i in range(1,n+1):
sum=sum+(x**i)/factorial(i+1)

print(" the sum of the series is",sum)

main()
########### output #############
'''enter the value for x5
enter the no of terms4
the sum of the series is 781.0'''

OUTPUT:
PROGRAM N0.3
SOURCE CODE:

n=int(input("enter the of lines to be generated"))


c=1

for i in range(1,n+1):
print(' '*(n-i),end="")
print('*'*c)
c=c+2

OUTPUT :
PROGRAM NO. 4:
SOURCE CODE:
adults = int(input("Enter the number of adults (age 18 and above): "))
children = int(input("Enter the number of children (age 5 to 17): "))
kids = int(input("Enter the number of kids (age below 5): "))
print("TICKET DETAILS:")
print("Adults (age 18 and above):",adults)
print("Children (age 5 to 17):",children)
print("Kids (age below 5):",kids)
print("Total Fare Collected:",(adults*50)+(children*20)+(kids*0))

OUTPUT:
PROGRAM NO. 5:

SOURCE CODE :

def ModifyList(L):

for i in range(len(L)):

if L[i] % 10 == 5:

L[i] = 1

else:

L[i] = 0

return L

# Sample RUN:

my_list = [12, 105, 20, 25, 30, 35]

modified_list = ModifyList(my_list)

print(modified_list)

OUTPUT:
PROGRAM NO. 6:
SOURCE CODE:
def minmax(t): # Method to compute minimum and maximum value
min=max=t[0]
for i in range(1,len(t)):
if t[i]>max:
max=t[i]
if t[i]<min:
min=t[i]
return min,max
############## Main #################
L=[]
print(" Enter the elements for Tuple")
for i in range(5):
x=int(input("enter the value"))
L.append(x)
t=tuple(L)
print("Elements of tuple are",t)

x,y=minmax(t) # Calling method to get min max value

print(" the minimum value",x)


print(" the maximum value",y)

OUTPUT :
PROGRAM NO. 7:
SOURCE CODE:
def INDEX_LIST(L):
indexlist = []
for i in range(len(L)):
if L[i] != 0:
indexlist.append(i)
return indexlist

# Test the function


L = [0, 1, 0, 2, 0, 3, 0, 4]
result = INDEX_LIST(L)
print(result)

OUTPUT :
PROGRAM NO. 8:
SOURCE CODE:
def createfile(): # adding lines to file

infile=open("poem.txt","a")
ch='y'
while ch=='y' or ch=='Y':
s=input("enter line")
infile.write(s+"\n")
ch=input("do you wish to continue")
print("Lines successfully added in file")
infile.close() #closing file

def generatefreq(): # Generating frequency of words


infile=open("poem.txt","r")
s=infile.readlines()
infile.close()
freq={} #dictionry to store frequency
a=0
for i in s:
k=i.rstrip("\n").lower()
k=k.split()
for x in k:
if x in freq:
freq[x]+=1
a+=1
else:
freq[x]=1
a+=1

print("Frequency Chart is")


print("\t word \t\t Frequency")
#freq=sorted(freq)
sum=0
for i in freq:
print("\t",i,"\t\t",freq[i])
sum+=freq[i]

print(sum ,"\t",a)
def longline():
infile=open("poem.txt","r")
s=infile.readlines()
infile.close()
max=" "
for i in s:
if(len(i)>len(max)):
max=i
print("the line with max length is")
print(max)

ch="Y"
while ch=='y' or ch=='Y':
print("1. Create stry.txt file\n\
2. Print freqency table of words\n\
3.Print longest line")
choice=int(input("enter your choice"))

if choice==1:
createfile()
elif choice==2:
generatefreq()
elif choice==3:
longline()
else:
print("invlid choice")
ch=input("do you wish to continue")
OUTPUT :
PROGRAM NO. 9:
SOURCE CODE:
def removalofa(fname):
with open(fname, 'r') as f:
lines = f.readlines()
with open('destination_file.txt', 'w') as d:
for i in lines:
if 'a' not in i:
d.write(i)
def beforeremoval():
infile=open("poem.txt","r")
s=infile.read()
infile.close()
print("Original contents Bedore removal")
print(s)
def afterremoval():
infile=open("poem2.txt","r")
s=infile.read()
infile.close()
print("New file after removal of letter a")
print(s)

# Calling Methods
beforeremoval()
fname="poem.txt"
removalofa(fname)
afterremoval()

OUTPUT :
PROGRAM NO. 10:
SOURCE CODE:
import pickle
def create():
f=open('Applicants.dat','wb')
f.close()
def add():
f=open('Applicants.dat','ab')
AppId=input('Enter Id of applicant')
AName=input('Enter applicant name')
Qualification=input('Enter qualification of applicant')
x=[AppId,AName,Qualification]
pickle.dump(x,f)
f.close()
def display():
f=open('Applicants.dat','rb')
try:
while True:
y=pickle.load(f)
print(y)
except EOFError:
f.close()
def search():
f=open('Applicants.dat','rb')
search=input('Enter qualifications you want to search')
c=0
try:
while True:
y=pickle.load(f)
if y[2].lower()==search.lower():
print(y)
c+=1
except EOFError:
if c==0:
print('No application of the searched qualfication present')
f.close()
def modify():
f=open('Applicants.dat','rb+')
c=int(input('What you want to modify? 1-Applicant name 2-Applicant qualification'))
Id=input('Enter applicant id whose details is to be modified')
try:
while True:
x=f.tell()
y=pickle.load(f)
if y[0]==Id:
if c==1:
name=input('Enter new name')
y[1]=name
f.seek(x)
pickle.dump(y,f)
f.close()
break
elif c==2:
qualify=input('Enter new qualification')
y[2]=qualify
f.seek(x)
pickle.dump(y,f)
f.close()
break
else:
print('Choose correct option')
f.close()
break
except EOFError:
print('Applicant id not found')
f.close()
while True:
print('''Choices are
1-Create file 2-Add applicant3-Display4-Search on basis of qualificatioon5-
Modify6Quit''')
ch=int(input('Enter a choice'))
if ch==1:
create()
elif ch==2:
add()
elif ch==3:
display()
elif ch==4:
search()
elif ch==5:
modify()
elif ch==6:
print('Program Terminated')
break
else:
print('Input correct choice')

OUTPUT :
PROGRAM NO. 11:
SOURCE CODE:
import csv
def create() :
f=open("MyFriend.csv","w")
print("CSV FILE CREATED SUCCESFULLY")
def add():
f=open(" MyFriend.csv","w")
wobj=csv.writer(f)
n=int(input("how many data is to be added"))
for i in range(n):
name=input("enter your friends name")
fco=int(input("enter contact no."))
fem=input("enter email")
fad=input("enter the address")
l=[name, fco, fem,fad]
wobj.writerow(l)
ch=input("do you want o to add more data")
if ch.lower=="n":
break
def search():
f=open("MyFriend.csv","r")
robj=csv.reader(f)
for i in robj:
fphno=int(input("enter phone number to be searched"))
if fphno in i:
print (i)
else:
print ("record not found")
def display():
f=open(" MyFriend.csv","r")
robj=csv.reader(f)
for i in robj:
print(i)
while True:
print ("1-to create file \n2-to add friend \n3-to search friend \n4-display
\n5-quit")
ch=int(input("enter choice"))
if ch==1:
create()
elif ch==2:
add()
elif ch==3:
search()
elif ch==4:
display()
else:
break
OUTPUT :
PROGRAM NO.12:
SOURCE CODE:
NoVowel=[]

def pushnv(n):
for word in n:
flag=0
for j in word:
if j in "AEIOUaeiou":
flag=1
break
if flag==0:
NoVowel.append(word)
def pop():
for i in range(len(NoVowel)):
print("Deleted elemnet is",NoVowel.pop())
else:
print("stack is empty")

## Main Program

N=eval(input("enter the list of name"))


pushnv(N)
pop()
enter the list of name['hello','cry','not','Try']
PROGRAM NO.13:
SOURCE CODE:
stk=[]
count=0

def push(sitem):
global count
for i in sitem.keys():
if sitem[i]>75:
stk.append(i)
count=count+1

sitem={}
for i in range(5):
try:
sitem[input("enter the stationary name")]=int(input("enter the price"))
except:
print("error occured")
push(sitem)
print("elements pushed with the price >75",count)
PROGRAM NO.14:
SOURCE CODE:
Create table club(CoachId int primary key,CoachName varchar(50) not null,Age
int not null,Sports char(30),DateofApp date,Pay int,Sex char(1));
PROGRAM NO.15:
SOURCE CODE:
insert into club values(1,'Kukreja',35,'Karate','1996/03/27',10000,'M');
insert into club values(2,'Ravina',34,'Karate','1998-01-20',12000,'F');
insert into club values(3,'Karan',32,'Squash','2000-02-19',20000,'M');
insert into club values(4,'Tarun',33,'Basket Ball','2005-01-01',15000,'M');
insert into club values(5,'Zubin',36,'Swimming','1998-02-24',7500,'M');
insert into club values(6,'Ketaki',33,'Swimming','2001-12-23',8000,'F');
Select * from club;
PROGRAM NO.16:
i)List all coaches whose sports is swimming or karate.
select * from club where sports="swimming" or sports=’Karate’;

ii)List all details sorted in ascending order of age.


select * from club order by age;

iii)Display Sports which have more than one coach.


select sports from club group by sports having count(*)>1;
iv)Display the number of Sports played in Club.
select count( distinct sports) from club;

v)List all male Coaches having pay in range of 5000 to 10000.


select * from club where sex='M' and pay between 5000 and 10000;
PROGRAM NO.17:
SOURCE CODE:
create table Company( CID int Primary key,Name varchar(30) Not Null,
City varchar(30) Not Null, PName varchar(30) Not Null);

create Table Customer(Sustid int primary key,Name varchar(40) Not Null,price int Not
Null,Qty int Check(qty>0),CID int references company(cid));
PROGRAM NO.18:
SOURCE CODE:
insert into company values(111,'Sony','Delhi','TV');
insert into company values(222,'Nokia','Mumbai','Mobile');
insert into company values(333,'Onida','Delhi','TV');
insert into company values(444,'Blackberry','Mumbai','Mobile');
insert into company values(555,'Samsung','Chennai','Mobile');
insert into company values(666,'Dell','Delhi','Laptop');
insert into customer values(101,'Rohan Sharma',70000,20,222);
insert into customer values(102,'Deepak Kumar',50000,10,666);
insert into customer values(103,'Mohan Kumar',30000,5,111);
insert into customer values(104,'Sahil Bansal',35000,3,333);
insert into customer values(105,'Neha Soni',25000,7,444);
insert into customer values(106,'Sonal Agarwal',20000,5,333);
insert into customer values(107,'Arjun Singh',50000,15,666);
PROGRAM NO.19:.
1) Display those company names having price less than 30000.
select c.name from company c ,customer c1 where c.cid=c1.cid and
c1.price>30000;

2) To increase price by 1000 for those customers whose name starts with
‘S’.
update customer set price=price+1000 where name like 's%';

3) To display Company details in reverse alphabetical order.


select * from company order by name desc;
4) To display customer details along with product name and company name
of the product.
select c.cid,c.name,c.price,c1.name,c1.pname from company
c1,customer c where c.cid=c1.cid;

5) To display details of companies based in Mumbai or Delhi.


select * from company where city in('Delhi','Mumbai');
PROGRAM NO.20:
SOURCE CODE:
import mysql.connector as sq

con=sq.connect(host="localhost",user="root",database="GAMES",passwd="lpc@1
23")

if con.is_connected():
cr=con.cursor()
choice='Y'
while choice=="Y":

a=int(input("enter the coachId"))


b=input("enter the Coach name")
c=int(input("enter age"))
d=input("enter the sports")
e=input("enter the date")
f=int(input("enter pay"))
g=input("enter the Gender M/F")

cr.execute("insert into club


values({},'{}',{},'{}','{}',{},'{}'".format(a,b,c,d,e,f,g))
con.commit()

print("record inserted")
choice=input("do you wish to continueY/N").upper()
else:
print("connection could not be established")
con.close()
PROGRAM NO.21:
SOURCE CODE:
import mysql.connector as sq

con=sq.connect(host="localhost",user="root",password="lpc@123",database="MY
ORG”)
if con.is_connected():
cr=con.cursor()
choice='Y'
cr.execute("UPDATE CUSTOMER SET PRICE=PRICE+PRICE*.10")
print("recordS UPDATED")
else:
print("connection could not be established")
con.close()
PROGRAM NO.22:
SOURCE CODE:
import mysql.connector as sq

con=sq.connect(host="localhost",user="root",password="lpc@123",database="MY
ORG")
if con.is_connected():
cr=con.cursor()
choice='Y'
cr.execute("DELETE FROM CUSTOMER WHERE NAME LIKE
‘%KUMAR%’ ”)
print("recordS UPDATED")
else:
print("connection could not be established")
con.close()

You might also like