Class 12-CS Practical File 2023 Sample 1
Class 12-CS Practical File 2023 Sample 1
ROLL NUMBER :
CLASS : XII-A
1. WAP to input a list and find the minimum and maximum 19/04/2023
value along with its position
2. WAP to input a list and store the positive and negative 19/04/2023
number from the list in two separate lists and print the same.
8. Program to read the content of file and display the total 08/07/2023
number of consonants, uppercase, vowels , lowercase and
digits characters
9. Program to read and display file content line by line with 08/07/2023
each word separated by #.
10. Program to read the content of file line by line and write it to 08/07/2023
another file except for the lines which contains “a” letter in i
11. Consider a dictionary with keys as course name and fee as 21/07/2023
value. Write a program to push the course name in stack
where the fee is more than 10000. Pop and display the
contents of stack on the screen.
S.NO AIM/PRACTICAL DATE SIGN
13. Program to create binary file to store Rollno and Name, 21/07/2023
Search any Rollno and display name if Rollno found
otherwise “Rollno not found”
17. Write brief detail about SQL and its commands 06/10/2023
27. Program to connect with database and delete the record of 17/11/2023
entered employee number
19/04/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 1
AIM: WAP to input a list and find the minimum and maximum value along
with its position
INPUT:
OUTPUT:
______________________________________________________
19/04/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 2
AIM: WAP to input a list and store the positive and negative number from the
list in two separate lists and print the same.
INPUT:
OUTPUT:
______________________________________________________
19/04/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 3
AIM: WAP to count and display the number of vowels, consonants uppercase
. and lowercase characters in a string.
INPUT:
STR=input("enter a string")
Ucase=Lcase=0
Vcount=Ccount=0
for i in STR:
if i in ["a","e","i","o","u","A","E","I","O","U"]:
Vcount += 1
else:
Ccount += 1
if i.isupper():
Ucase +=1
if i.islower():
Lcase += 1
print("the total number of vowel is:",Vcount)
print("the total number of consonants is:",Ccount)
print("the total number of uppercase letter is:",Ucase)
print("the total number of lowercase letter is:",Lcase)
OUTPUT:
______________________________________________________
27/04/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 4
INPUT:
while True:
print("press 1: perfect number")
print("press 2: armstrong number")
print("press 3: palindrome number")
choice=int(input("enter the choice 1/2/3 : "))
if choice==1:
num=int(input("enter the number:"))
s=0
for i in range(1,num):
if num%i==0:
s=s+i
if s==num:
print(num,"is a perfect number")
else:
print(num,"is not a perfect number")
if choice==2:
num=int(input("enter the number:"))
s=0
temp=num
while temp!=0:
d=temp%10
s=s+d**3
temp=temp//10
if num==s:
print(num,"is a armstrong number")
else:
print(num,"is not a armstrong number")
if choice==3:
num=int(input("enter the number:"))
rev=0
temp=num
while temp!=0:
rem=temp%10
rev=rev*10+rem
temp=temp//10
if num==rev:
print(num,"is a palindrome")
else:
print(num,"is not a palindrome")
break
OUTPUT:
for palindrome :
______________________________________________________________
27/04/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 5
AIM : WAP to input a string and check whether it is a palindrome string or not
INPUT :
n=input("Enter a String:")
l=len(n)
mid=l//2
rev=-1
for i in range(0,mid):
if n[i]==n[rev]:
rev=rev-1
else:
print("String is not palindrome")
break
else:
print("String is Palindrome")
OUTPUT :
When string is a palindrome:
______________________________________________________________
27/04/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 6
INPUT :
while True:
print("press 1: for fibonacci series")
print("press 2: for the factorial of a number")
print("press 3: for exiting")
choice=int(input("Enter the choice"))
if choice==1:
num=int(input("Enter the number of element for the fibonacci series"))
num_1=0
num_2=1
print(num_1,end=" ")
print(num_2,end=" ")
for i in range(3,num+1):
num_3=num_1+num_2
print(num_3,end=" ")
num_1=num_2
num_2=num_3
print()
print("______________________________")
if choice==2:
num=int(input("Enter the number"))
temp=num
fac=1
while num>=1:
fac=fac*num
num=num-1
print("Factorial of",temp,"is",fac)
print("______________________________")
if choice==3:
for_exiting=input("do you wish to exit ?(y/n)")
if for_exiting in ["Y","y"]:
print("exiting the program")
break
else:
print("_____________________________")
OUTPUT:
______________________________________________________________
27/04/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 7
INPUT :
STRING=input("Enter the string/sentence:")
word=input("Enter the word to be searched in a string:")
lst=STRING.split( )
for i in range(0,len(lst)):
if lst[i]==word:
print("the word is found")
OUTPUT :
______________________________________________________________
08/07/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 8
AIM :Program to read the content of file and display the total number of
consonants, uppercase, vowels , lowercase and digits characters.
INPUT :
f=open("PR8.txt","r")
v_count=c_count=u_count=l_count=digit_count=0
a=f.read()
for i in a:
if i in "AEIOUaeiou":
v_count+=1
if i in "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz":
c_count+=1
if i.isupper():
u_count+=1
if i.islower():
l_count+=1
if i.isdigit():
digit_count+=1
print("the number of vowels in file is:",v_count)
print("the number of consonants in file is:",c_count)
print("the number of upper letters in file is:",u_count)
print("the number of lower letters in file is:",l_count)
print("the number of digits in file is:",digit_count)
f.close()
OUTPUT: FILE
______________________________________________________________
08/07/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 9
AIM : Program to read and display file content line by line with each word
separated by #.
INPUT :
f=open('myfile.txt','r')
for i in f:
words = i.split()
replaced= '#'.join(words)
print(replaced)
OUTPUT :
File:
______________________________________________________________
08/07/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 10
AIM:Program to read the content of file line by line and write it to another file
except for the lines which contains “a” letter in it
INPUT:
file_1=open("student.txt","r")
file_2=open("transfer.txt","w")
r=file_1.readlines()
flag=0
for i in r:
if i[0] != "a":
file_2.write(i)
flag=1
if flag==1:
print("write successful")
else:
print("no statement starts with a")
file_1.close()
file_2.close()
OUTPUT :
______________________________________________________________
21/07/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 11
AIM:Consider a dictionary with keys as course name and fee as value. Write
a program to push course name in stack where the fee is more than
10000. Pop and display contents of stack on the screen
INPUT:
dic={"chemistry":12000,"physic":7000,"biology":9500,"mathematics":15000}
stack=[]
for i in dic:
if dic[i]>10000:
stack.append(i)
while True:
if stack==[]:
print("the stack is empty")
break
else:
print(stack.pop())
OUTPUT:
______________________________________________________________
21/07/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 12
AIM: Write a program to pass an integer list as stack to a function and push
only those elements in the stack which are divisible by 7. Also write a
function to pop and display the stack
INPUT:
def Push():
for i in num_list:
if i%7==0:
stack.append(i)
def Pop():
while True:
if stack==[]:
print("stack is empty")
break
else:
print(stack.pop())
num_list=eval(input("Enter a list of number :"))
stack=[]
Push()
Pop()
OUTPUT:
______________________________________________________________
21/07/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 13
AIM: Program to create binary file to store Rollno and Name, Search any
Rollno and display name if Rollno found otherwise “Rollno not found”
INPUT:
import pickle
f1=open("student.dat","ab")
f2=open("student.dat","rb")
num=int(input("Enter the number of student whose data is to be entered :"))
for i in range(num):
roll=int(input("Enter the roll number of the student :"))
name=input("Enter the name of the student :")
record=[roll,name]
pickle.dump(record,f1)
f1.close()
search_roll=int(input("Enter the roll number of the student to be searched :"))
flag=0
while True:
try:
r=pickle.load(f2)
if r[0]==search_roll:
print("The name of the student is :",r[1])
flag=1
except EOFError:
break
if flag==0:
print("Roll number is not found")
f2.close()
OUTPUT:
file
______________________________________________________________
18/08/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 14
AIM: Program to create binary file to store Rollno,Name and Marks and
update marks of entered Rollno
INPUT:
import pickle
f1=open("marks.dat","ab")
f2=open("marks.dat","rb")
num=int(input("Enter the number of student whose data is to be entered :"))
for i in range(num):
roll=int(input("Enter the roll number of the student :"))
name=input("Enter the name of the student :")
marks=int(input("Enter the marks :"))
record=[roll,name,marks]
pickle.dump(record,f1)
f1.close()
search_roll=int(input("Enter the roll number of the student to be searched :"))
flag=0
while True:
try:
r=pickle.load(f2)
if r[0]==search_roll:
updated_marks=int(input("Enter the new marks"))
r[2]=updated_marks
flag=1
except EOFError:
break
if flag==0:
print("Student not found")
else:
print("Marks updated successfully")
f2.close()
OUTPUT:
File:
______________________________________________________________
18/08/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 15
AIM: Program to create CSV file and store empno,name,salary and search
any empno and display name,salary and if not found appropriate
message
INPUT:
import csv
f1=open("empolyee.csv","a", newline="")
w=csv.writer(f1)
num=int(input("Enter the number of employee whose data is to be entered :"))
for i in range(num):
empno=int(input("Enter the employee number :"))
name=input("Enter the name of the employee :")
sal=int(input("Enter the salary of the employee :"))
data=[empno,name,sal]
w.writerow(data)
f1.close()
search=int(input("Enter the employee no. of the employee to be searched :"))
flag=0
f2=open("emp.csv","r")
r=csv.reader(f2)
for i in r:
if i[0]==search:
print("name of the employee is :",i[1])
print("salary of the employee is :",i[2])
flag=1
if flag==0:
print("employee not found")
f2.close()
OUTPUT:
File:
______________________________________________________________
18/08/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 16
INPUT:
import random
result=random.randint(1,6)
print("the result of the dice is :",result)
OUTPUT:
______________________________________________________________
06/10/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 17
INPUT:
SQL:
The Structured Query Language (SQL) is a language that enables you to
create and operate on relational databases, which are sets of related
information stored in tables.
______________________________________________________________
06/10/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 18
AIM: Write the SQL command/query based on Creation, Insertion, Deletion &
pattern Matching.
INPUT:
1. Write the command to create the table STUDENT
OUTPUT:
OUTPUT:
3. Write the command to select distinct Streams in the table STUDENT
4. Write the command to display details of all students whose name starts
with D.
5. Write the command to display details of all students that have second
character ‘i’ in their name
06/10/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 19
AIM: Write the SQL command/query based on Alter, Update, Deletion and
Sorting with reference to the STUDENT table.
INPUT:
1. Write a command to update marks of student having admission number
8765 to 76
Output:
4. Write a command to display Name and Stream of all students who have
Nonmedical stream
Output:
Output:
______________________________________________________________
26/10/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 20
INPUT:
1. Write a command to compute sum of marks of students in student table
______________________________________________________________
26/10/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 21
AIM: Write the SQL command/query based on Group by and having clause
with reference to the STUDENT table
INPUT:
1. Write command to count number of students in each Streams
______________________________________________________________
26/10/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 22
AIM; Write the SQL command/query based on Single Row functions with
reference to the STUDENT table.
INPUT:
1. Write command to extract the first 2 characters from Name column
5. Write command to extract the last three characters from the Name
column
______________________________________________________________
16/11/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 23
INPUT:
1. To display names of participants along with workshop titles for only
those workshops that have more than 2 speakers
_________________________________________________________
16/11/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 24
AIM: Program to connect with database and store record of employee and
display records
INPUT:
import mysql.connector as mycon
conn=mycon.connect(host="localhost",user="root",password="Shubh@1904",
database="practical")
cur=conn.cursor()
cur.execute("insert into employee values({},'{}','{}',{})".format(121,"Kartik
singh","IT",40000))
cur.execute("insert into employee values({},'{}','{}',{})".format(324,"Deepa
kumari","HR",34000))
cur.execute("insert into employee values({},'{}','{}',{})".format(754,"Mahesh
singh","MARKETING",23500))
cur.execute("insert into employee values({},'{}','{}',{})".format(432,"Anuj
kumar","HR",35000))
cur.execute("insert into employee values({},'{}','{}',{})".format(234,"Aarti","IT",
45000))
conn.commit()
print("Data inserted successfully")
cur.execute("select * from employee")
c=cur.fetchall()
for i in c:
print(i)
conn.close()
OUTPUT :
Python :
Sql:
______________________________________________________________
16/11/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 25
INPUT:
import mysql.connector as mycon
conn=mycon.connect(host="localhost",user="root",password="Shubh@1904"
, database="practical")
cur=conn.cursor()
cur.execute("select * from employee")
c=cur.fetchall()
flag=0
number=int(input("enter the employee number to be searched"))
for i in c:
if i[0]==number:
print("the employee number is :",i[0])
print("the employee name is :",i[1])
print("the employee department is :",i[2])
print("the employee salary is :",i[3])
flag=1
if flag==0:
print("the employee is not found")
OUTPUT :
______________________________________________________________
17/11/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 26
AIM : Program to connect with database and update the employee record of
entered empno
INPUT:
import mysql.connector as mycon
conn=mycon.connect(host="localhost",user="root",password="Shubh@1904",
database="practical")
emp_num=int(input("Enter employee number to update :"))
flag=0
cur=conn.cursor()
cur.execute("select * from employee")
c=cur.fetchall()
for i in c:
if i[0]==emp_num:
print("employee number",emp_num,"found")
new_name=input("enter the new name :")
new_dept=input("enter the new department :")
new_sal=int(input("enter the new salary :"))
cur.execute("update employee set ename='{}',dept='{}',salary={} where
empno={}".format(new_name,new_dept,new_sal,
emp_num))
conn.commit()
print("data updated successfully")
flag=1
if flag==0:
print("employee not found")
conn.close()
OUTPUT:
Python :
SQL:
______________________________________________________________
17/11/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 27
AIM: Program to connect with database and delete the record of entered
employee number
INPUT:
import mysql.connector as mycon
conn=mycon.connect(host="localhost",user="root",password="Shubh@1904",
database="practical")
emp_num=int(input("Enter employee number to delete the data from :"))
cur=conn.cursor()
flag=0
cur.execute("select * from employee")
c=cur.fetchall()
for i in c:
if i[0]==emp_num:
cur.execute("delete from employee where empno={}".format(emp_num))
print("data deleted successfully")
flag=1
conn.commit()
if flag==0:
print("data not found to be deleted")
conn.close()
OUTPUT:
Python:
SQL:
______________________________________________________________