Siddhant Part 1
Siddhant Part 1
D SARASWATI BAL
MANDIR SCHOOL
NAME : SIDDHANT
CLASS : XII A
ROLL NUMBER : 27
2024 – 2025
COMPUTER SCIENCE
PRACTICAL
INDEX
Write a program to input a string and check whether it’s
a palindrome string or not.
if str1==str1[-1::-1]:
print("It is a Palindrome")
else:
output:
..
Write a program to find the maximum and minimum
number in the list.
maximum=list1[0]
minimum=list1[0]
for i in list1:
if i>maximum:
maximum=i
if i<minimum:
minimum=i
output:
Write a program to input a string and display:
-The number of lowercase letters.
-The number of uppercase letters.
-The number of digits.
-The number of special characters.
Program: dict1={}
s=int(input("no. of records:"))
for i in range(s):
name=input("enter the name of
employee:")
phone no=int(input("enter phone no:"))
dict1[name]=phone no
print("dictionary:",dict1)
list1=list(dict1.items())
list1.sort()
dict1=dict(list1)
print("dictionary in ascending order by
name:",dict1)
output:
Write a function in python to count the number of lines
in a text file “story.txt” which is staring with an
alphabet ’A’.
count=0
for i in list1:
if i[0]=='A' or i[0]=='a':
count+=1
count lines('story.txt')
output:
Write a function in python to read lines from ‘poem.txt’
and count how many times the word ‘india’ exists in file
count=0
count+=i. count('India')
Count India()
Output:
Write a program rotates the elements of a list so that
the element at the first index moves to the second
index, the element in the second index moves to the
third index, etc., and the element in the last index
moves to the first index.
print("list:",list1)
list1[0],list1[i]=list1[i],list1[0]
print("list in rotation:",list1)
output:
Write a python code to accept a set of integers number
in a tuple find and display the numbers are prime.
list1=[]
for i in tup1:
for j in range(2,i//2+1):
if i% j==0:
break
else:
list1+=[i]
print("tuple: ",tup1)
output:
Write a function L shift(Arr ,n) in python which accepts
a list Arr of numbers and n is a numeric value by which
all elements of the list are shifted to list.
Program: def L shift (Arr, n):
for i in range(n):
for j in range(-1,-len(Arr)-1,-1):
Arr[j],Arr[0]=Arr[0],Arr[j]
print("List after shifted by {}:
".format(n),Arr)
list1=eval(input("Enter a list of numbers: "))
sft=int(input("Shift left by "))
L shift(list1,sft)
Output:
Write a program to implement a stack for this book
details (book no., book name). that is now each item
node of this stack contains two type of information a
book no. and its name just implement push, pop and
display operations.
Query:
Query:
Query:
Write the query to redefine the NAME field size into
VARCHAR(40) in the students table.
Query:
Query:
TABLE NAME: DOCTOR
Query:
Query:
Write the query to display the patient id, name and age
who Fixed the appointment on September month.
Query:
Query:
write the query to display the sum of the salary of the
doctors department wise.
Query:
Query:
.
Write the query to display the average salary of each
dept from doctor table.
Query:
Query:
Write the query to delete record of the doctor id ‘D08’
and ‘D06’ from the table.
Query:
Program:
ans='Y'
column=[]
column+=[x]
constraints=[]
str1+=j+' '
str1+=')'
else:
str1+=','
cursor. execute(str1)
record+=(len(column)-1)*"'{}',"+"'{}')"
ans='y'
list1=[]
for i in column:
list1+=[input("Enter {} :".format(i[0]))]
print(list1)
print("Data Inserted")
con. close()
output:
Write a python program to search the records
from the table based on the exam number and
display the details of the student.
Program:
con=mym.connect(host='localhost',user='root',passwo
rd='siddhant',database='student')
cursor=con. cursor()
try:
if details!=None:
else:
except Exception:
con. close()
output:
Write a python program to update the student
mark on table based on the exam no given by the
user. If record not found display the appropriate
message.
Program:
con=mym.connect(host='localhost',user='root',passwo
rd='siddhant',database='student')
cursor=con. cursor()
try:
if detail!=None:
cursor. execute(statement)
con .commit()
else:
except Exception:
con. close()
Output:
Create a CSV file which should contains the
employee details and to search the particular
employee based on emp no and display the
details.
Program:
import csv
readers=csv. readers(file)
for i in readers:
if int(i[1])==emp no:
break
else:
file. close()
output:
Create a CSV file which should contains the
employee details and to update their salary
based on emp no.
Program:
import csv
found=False
reader=csv. reader(file)
writer=csv .writer(file)
for i in reader:
if int(i[1])==search:
i[2]=salary
found=True
new data+=[i]
if found==True:
file. seek(0)
print("data Updated")
else:
file. close()
output:
Create a CSV file which should contains the
employee details
and to delete the particular record based on emp
no.
Program:
import csv
new data=[]
found=False
reader=csv. reader(file)
for i in reader:
if int(i[1])==search:
found=True
continue
new record+=[i]
file .close()
if found==True:
writer=csv. writer(file)
print("data Deleted")
else:
output:
Create a binary file which should contain the
student details and to search the particular.
Program:
import pickle
file=open('student.dat',' r b')
try:
while True:
s=pickle .load(file)
if s[1]==search:
file .close()
break
file. close()
output:
Create the binary file which should contains the
details and to delete the particular student
based on roll no and display the details.
Program:
import pickle
found=False
s=pickle. load(file)
if s[row][1]==search:
del s[row]
found=True
break
if found==True:
file. seek(0)
print("Record Removed")
else:
output:
.
Create a binary file which should contains the
students details and to update the particular
student based on roll no and display the details.
Program:
import pickle
found=False
con=pickle. load(file)
if records[row][1]==search:
found=True
break
if found==True:
file. seek(0)
file. Close()
output: