[go: up one dir, main page]

0% found this document useful (0 votes)
15 views54 pages

Siddhant Part 1

Uploaded by

brazillalajssgs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views54 pages

Siddhant Part 1

Uploaded by

brazillalajssgs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 54

S . S .

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.

Write a program to create a dictionary containing the


names of the students as keys and the marks secures
by them in CS as the values respectively. Display the
names and marks of the students who have secured 80
and above, also display the number of students
securing 80 marks and above.

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.

Write a program to input the name and phone number


of number of employees. Create a dictionary to contain
key and values as name and phone number of the
employee. Display the key value pairs in ascending
order of the names.

Write a function in python to count the number of lines


in a text file “story.txt” which is staring with an
alphabet ’A’.

Write a function display word ( ) in python to read lines


from a text file’story.txt’ and display those words, which
are less than 4.

Write a function in python to read lines from ‘poem.txt’


and count how many times the word ‘india’ exists in file
Take a sample text file and find the most commonly
occurring word. Also, list the frequencies of word in the
text file .

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.

Write a python code to accept a set of integers number


in a tuple find and display the numbers are prime.

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.

Write a binary file which should contain the student


details and to search the particular.

Create the binary file which should contains the


students details and to update the particular student
based on roll on. and display the details.

Create the binary file which should contains the


students details and to delete the particular student
based on roll on. and display the details.
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.

Create a CSV file which should contains the employee


details and to search the particular employee based on
emp_no and display the details.

Create a CSV file which should contains the employee


details and to update their salary based on emp no.

Create a CSV file which should contains the employee


details and to delete the particular record based on
emp no.

Write a python program to create the table and insert


the record into the table by getting the data from the
user and to store in the my SQL.
Write a python program to search the records from the
table based on the exam number and display of the
student.

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.

Write a program to find the maximum and minimum


number in the list.
Write a program to input a string and check whether it’s
a palindrome string or not.

program: str1=input("Enter a String: ")

if str1==str1[-1::-1]:

print("It is a Palindrome")

else:

print("It is not a Palindrome")

output:

..
Write a program to find the maximum and minimum
number in the list.

Program: list1=eval(input("Enter a list: "))

maximum=list1[0]

minimum=list1[0]

for i in list1:

if i>maximum:

maximum=i

if i<minimum:

minimum=i

print("Minimum Number: ",minimum)

print("Maximum Number: ",maximum)

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: str1=input("Enter a String: ")


Uppercase ,lowercase ,digit ,special=0,0,0,0
for i in str1:
if i.is upper() and i!=' ':
uppercase+=1
elif i.is lower() and i!=' ':
lowercase+=1
elif i.is digit() and i!=' ':
digit+=1
else:
special+=1
print("Number of Uppercase letters in string:
",uppercase)
print("Number of Lowercase letters in string:
",lowercase)
print("Number of Digits in string: ",digit)
print("Number of Special character in string:
",special)
output:
Write a program to create a dictionary containing the
names of the students as keys and the marks secures
by them in CS as the values respectively. Display the
names and marks of the students who have secured 80
and above, also display the number of students
securing 80 marks and above.
Program: dict1={}
Ans='y'
while Ans=='y':
name=input("enter name of the
student:")
marks=int(input("enter marks:"))
dict1[name]=marks
Ans=input("enter more data(Y/N):")
s=0
print(" student who scored 80 and above:")
for i in dict1:
if dict1[i]>=80:
print(i,dict1[i])
s+=1
print("number of students who scored 80 and
above:",s)
output:
Write a program to input the name and phone number
of number of employees. Create a dictionary to contain
key and values as name and phone number of the
employee. Display the key value pairs in ascending
order of the names.

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’.

Program: def count lines(file name):

count=0

with open(filename) as file:

list1=file .read lines()

for i in list1:

if i[0]=='A' or i[0]=='a':

count+=1

print("Number of lines starting with A are:


",count)

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

Program: def Count India():

with open('poem .txt ','r') as file:

count=0

for i in file. read lines():

count+=i. count('India')

print('Count of the word "India": ',count)

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.

Program: list1=eval(input("enter a list:"))

print("list:",list1)

for i in range (1,len(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.

Program: tup1=eval(input("Enter a Tuple: "))

list1=[]

for i in tup1:

for j in range(2,i//2+1):

if i% j==0:

break

else:

list1+=[i]

print("tuple: ",tup1)

print("List of prime numbers: ",list1)

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.

program: def push(stk, item):


Stk. append(Item)
def pop(Stk):
Top=len(Stk)-1
if Top==-1:
return 'underflow'
else:
Item=Stk. pop()
return Item
def Display(Stk):
Top=len(Stk)-1
if Top==-1:
print('Stack is empty')
else:
for i in range(Top,-1,-1):
print(Stk[i])
print('1.push')
print('2.pop')
print('3.display')
print('4.Exit')
Stk=[]
Top=None
while True:
choice=int(input("Enter your Choice:
"))
if choice==1:
book name=input('Enter book
name: ')
book no=int(input('Enter book
number: '))
Item=[book name, book no]
push(Stk ,Item)
elif choice==2:
Item=pop(Stk)
if Item=='underflow':
print('Stack is Empty')
else:
print('Deleted Item is', Item)
elif choice==3:
Display(Stk)
else:
break
output:
EXAMN NAME CLASSSEC MAR
O K
1201 PAVINDHAN XII A1 489
1202 ESHWAR XII A1 465
1203 BHARKAVI XII A2 498
1204 HARIPRIYA XII A2 400
1205 JAI PRADHAP XII NUL 398
L
1206 KAVIPRIYA XII A2 NULL
TABLE: STUDENTS
Write the query to create the above table and set the
constraints for the attributes. Examno-primary
key ,name-not null, marks check-marks should not
exceed 500.
Query:
(1201,'PAVINDHAN','XII','A1',489),
(1202,'ESHWAR','XII','A1',465),
(1203,'BHARKAVI','XII','A2',498),
(1204,'HARIPRIYA','XII','A2',400);

Write a query to insert the international records into the


table
Query:
Write the query to display all the student records who is
studying in A1 section.

Query:

Write the query to display the records whose marks is


not assigned.
Query:
Write the query to display whose marks in the range
400 to 450(both values are inclusive).
Query:

Write the query to display the student name, marks


who secured more than 400 and less than 487.
Query:
Write the query to display the details whose name is
starts with ‘P’ or ‘B’.
Query:

Write the query to display the student name and


section whose name contain ‘priya’.
Query:
Write the query to display all the details sort by name
in descending order.
Query:

Write the query to add 10 marks with the existing


marks as ‘updated marks’ and display the details.
Query:
Write the query to add a new column named as CITY
with the
data type VARCHAR(30) and apply the default
constraint ‘NOT MENTIONED’ in the students table.

Query:

Write the query to change the order of the column in


the students table as :
EXAMNO,NAME,CITY,CLASS,SEC,MARK

Query:
Write the query to redefine the NAME field size into
VARCHAR(40) in the students table.
Query:

Write the query to update the mark as 350 whose


marks is null
and update the section is A3 whose section is null.

Query:
TABLE NAME: DOCTOR

DOCID DNAME DEPT CITY SALARY

D01 ASHWATH ONCOLOGY CHENNAI 150000


AN

D02 RAMYA GYNAECOLO COIMBATOR 140000


GY E

D03 SRIRAM DENTAL BHOPAL 180000

D04 SANJAY CARDIOLOGY HYDERABAD 160000

D05 SRINITHI PEDIATRICS DELHI 120000

D06 SANTHOS PEDIATRICS BENGALURU 140000


H

D07 KARTHICK CARDIOLOGY JAIPUR 180000

D08 YASHIK GYNAECOLO AHMEDABAD 195000


GY

TABLE NAME : PATIENT

PATID PNAME APMDATE GENDER AGE DOCID

P01 SATHISH 2022/08/19 MALE 45 D01

P02 SUPRIYA 2022/09/21 FEMALE 23 D02

P03 ARUNA 2022/10/20 FEMALE 43 D08

P04 RAMESH 2022/08/25 MALE 84 D04

P05 KUMAR 2022/09/23 MALE 12 D02


P06 PRIYA 2022/09/14 FEMALE 10 D06

P07 ROOPA 2022/08/13 FEMALE 66 D03

P08 CHARLES 2022/10/12 MALE 24 D07


Write the query to create the patient table and keep
DOCID to be the foreign key with update and delete
cascade.

Query:

Write the query to display the count of male and female


patients in the age between 40 and 50.

Query:

Write the query to display the patient id, name and age
who Fixed the appointment on September month.
Query:

Write the query to display the number of doctors in


each dept.

Query:
write the query to display the sum of the salary of the
doctors department wise.

Query:

Write the query to display patient name, doctor name,


patient
Age and their appointment date from the tables

Query:

.
Write the query to display the average salary of each
dept from doctor table.

Query:

Write the query to display the maximum and minimum


salary of each department.

Query:
Write the query to delete record of the doctor id ‘D08’
and ‘D06’ from the table.

Query:

write the output of the followings queries after


executing the above question query. SELECT * FROM
DOCTOR; SELECT * FROM PATIENT.
Query:
Write a python program to create the table and insert
the record into the table by getting the data from the
user and to store in the my sql.

Program:

import my sql. connector as mym

con =mym. connect(user='root', password='siddhant',


host='localhost', database='student')

cursor = con. cursor()

table name=input("Enter name of table for creating: ")

cursor. execute("DROP TABLE IF EXISTS


{}".format(tablename))

ans='Y'

column=[]

while ans=='y' or ans=='Y':

x=eval(input("Enter column detail format


['name','datatype']: "))

column+=[x]

ans=input("Enter more column?(Y/N): ")

constraints=[]

ans=input("Add constraints on columns?(Y/N): ")

while ans=='y' or ans=='Y':

constraint=eval(input("Enter constraints for column


format['constraint name(column(s)name/condition)']:
"))
constraints+=[constraint]

ans=input("Enter more constraint?(Y/N): ")

column and constrains=column +constraints

str1='create table {}('.format(table name)

for i in range(0,len(column and constrains)):

for j in column and constrains[i]:

str1+=j+' '

if i+1==len(column and constrains):

str1+=')'

else:

str1+=','

cursor. execute(str1)

record="insert into {} values("

record+=(len(column)-1)*"'{}',"+"'{}')"

print("Table {} created". format (table name))

ans='y'

while ans=='y' or ans=='Y':

list1=[]

for i in column:

list1+=[input("Enter {} :".format(i[0]))]

print(list1)

cursor. execute(record. format(table name,*list1))


con. commit()

print("Data Inserted")

ans=input("Insert more data?(Y/N)")

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:

import mysql. connector as mym

con=mym.connect(host='localhost',user='root',passwo
rd='siddhant',database='student')

cursor=con. cursor()

try:

table name=input("Enter Table name: ")

exam no=int(input("Enter Exam no. of student to


search: "))

cursor. execute("select * from {} where exam


no={}”.format (table name ,exam no))

details=cursor .fetch one()

if details!=None:

print("The details of student with {} exam no


are :”.format (exam no),details)

else:

print("No records found")

except Exception:

print("Table Does Not Exist")

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:

import mysql. connector as mym

con=mym.connect(host='localhost',user='root',passwo
rd='siddhant',database='student')

cursor=con. cursor()

try:

table name=input("Enter name of table: ")

exam no=int(input("Enter exam number of student


whose marks you want to update: "))

cursor. execute('select * from {} where exam


no={}’.format (table name, exam no))

detail=cursor. Fetch one()

if detail!=None:

print("Details of student: ",detail)

new marks=input("Enter new marks: ")+'%'

statement='update {} set percentage="{}" where


exam no= {};'.format(table name ,new marks, exam
no)

cursor. execute(statement)

con .commit()
else:

print("No records found")

except Exception:

print("Table does not exist")

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

Emp no=int(input("Enter emp no of employee you are


searching: "))

file=open('student .csv ','r')

readers=csv. readers(file)

for i in readers:

if int(i[1])==emp no:

print('The employee details: ',i)

break

else:

print("Data not found")

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

file=open('student.csv ','r+', new line='')

search=int(input("Enter emp no of employee to


search: "))

new data =[]

found=False

reader=csv. reader(file)

writer=csv .writer(file)

for i in reader:

if int(i[1])==search:

print("Details of employee before updating: ",i)

salary=int(input("updated salary: "))

i[2]=salary

found=True

new data+=[i]

if found==True:

file. seek(0)

writer. Write rows(new data)

print("data Updated")
else:

print("No Data Found")

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

file=open('student.csv ','r', new line='')

search=int(input("Enter emp no of employee to delete:


"))

new data=[]

found=False

reader=csv. reader(file)

for i in reader:

if int(i[1])==search:

print("Details of employee: ",i)

found=True

continue

new record+=[i]

file .close()

if found==True:

file=open('update salary. Csv ','w', newline='')

writer=csv. writer(file)

writer. Write rows (new data)


file. close()

print("data Deleted")

else:

print("No Data Found")

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')

search=int(input("Enter roll no of student you want to


search: "))

try:

while True:

s=pickle .load(file)

if s[1]==search:

print('The details of the student are: ',s)

file .close()

break

except EOF Error:

print('No records found')

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

search=int(input("Enter roll no of student to delete: "))

found=False

file=open('student.dat ,'r b+')

s=pickle. load(file)

for row in range(len(records)):

if s[row][1]==search:

print('Details of student with {} roll no:’.


format(search), s[row])

del s[row]

found=True

break

if found==True:

file. seek(0)

pickle. dump(s, file)

print("Record Removed")

else:

print("No Record Found")


file. close()

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

search=int(input("Enter roll no of student to update: "))

found=False

file=open('student.dat ','r b+')

con=pickle. load(file)

for row in range(len(con)):

if records[row][1]==search:

print('Details of student with {} roll no: ‘.


format(search), con[row])

name=input("Enter Name of student: ")

roll no=int(input("Enter roll no of student: "))

class_=input("Enter class of student: ")

marks=int(input("Enter marks of students: "))

con[row]=[name ,roll no, class_, marks]

found=True

break

if found==True:

file. seek(0)

pickle. dump(con ,file)


print(“data updated”)
else:

print("No records found")

file. Close()

output:

You might also like