NSPV CS Practical File - 2023-2024
NSPV CS Practical File - 2023-2024
PRACTICAL PROGRAMS
FOR GRADE – XII
[2023-2024]
Prepared by:
2
EX.NO: 1
DATE:
SOURCE CODE:
result = 0
val1 = float (input ("Enter the first value :"))
val2 = float (input ("Enter the second value :"))
op= input ("Enter any one of the operator (+,-,*,/,//,%)")
if op == "+":
result = val1 + val2
elif op == "":
result = val1 - val2
elif op == "*":
result = val1 * val2
elif op == "/":
if val2 == 0:
print("Please enter a value other than 0")
else:
result = val1/val2
elif op == "//":
result = val1 // val2
else:
result = val1 % val2
print("The result is:",result)
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
3
SAMPLE OUTPUT:
***************************************************************************************
4
EX.NO: 2
DATE:
AIM:
To write a Python Program to display Fibonacci Series up to ‘n’ numbers.
SOURCE CODE:
First=0
Second=1
n=int(input("How many Fibonacci numbers you want to display?"))
if n<=0:
print("Please Enter Positive Integer")
else:
print(First)
print(Second)
for i in range(2,n):
Third=First+Second
First=Second
Second=Third
print(Third)
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
5
SAMPLE OUTPUT:
Python Executed Program Output:
*****************************************************************************************
6
EX.NO: 3
DATE:
AIM:
To write a menu driven Python Program to find Factorial and sum of list of numbers
using function.
A) SOURCE CODE:
def factorial(n):
fact = 1
for i in range(1, n+1):
fact = fact * i
return fact
x = int(input("Enter a Number: "))
result = factorial(x)
print( "Factorial of", x ,"is: ", result)
B) SOURCE CODE:
def sum_list(items):
sum = 0
for i in items:
sum = sum+i
return sum
lst = eval(input("Enter list items: "))
print("Sum of list items is: ", sum_list(lst))
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
7
SAMPLE OUTPUT:
Enter a Number: 5
8
EX.NO: 4
DATE:
AIM:
To Write a Python program to define the function Check(no1,no2) that take two numbers and
Returns the number that has minimum ones digit.
Source Code:
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
Sample Output:
**********************************************************************************
9
EX.NO: 5
DATE:
AIM:
SOURCE CODE:
import math
def Square(num):
S=math.pow(num,2)
return S
def Log (num):
S=math.log10(num)
return S
def Quad (X,Y):
S=math.sqrt(X**2+ Y**2)
return S
print("The Square of a Number is:", Square (5))
print("The Log of a Number is: ",Log(10))
print("The Quad of a Number is: ",Quad (5,2))
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
SAMPLE OUTPUT:
Python Executed Program Output:
***************************************************************************
10
EX.NO: 6
DATE:
SOURCE CODE:
import random
while True:
choice=input("Do you want to roll the dice (y/n): ")
n=random.randint(1,6)
if(choice=="y"):
print("\n Your Number is: ", n)
else:
break
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
SAMPLE OUTPUT:
**********************************************************************************
11
EX.NO: 7
DATE:
AIM:
To write a Python Program to Read a text file "Story.txt" line by line and display
each word separated by '#'.
SOURCE CODE:
file=open(r"D:\Name.txt","r")
lines=file.readlines()
for line in lines:
words=line.split()
for word in words:
print(word+"#",end=" ")
print(" ")
file.close()
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
SAMPLE OUTPUT:
Story.txt:
12
EX.NO: 8
DATE:
To write a Python Program to read a text file "Story.txt" and displays the number of
Vowels/ Consonants/ Lowercase / Uppercase/characters in the file.
SOURCE CODE:
file=open(r"D:\Name1.txt","r")
content=file.read()
vow=0
con=0
low=0
up=0
for ch in content:
if(ch.islower()):
low+=1
elif(ch.isupper()):
up+=1
ch=ch.lower()
if (ch in ['a','e','i','o','u']):
vow+=1
elif(ch in ['b','c','d', 'f','g', 'h','j','k', 'I','m','n','p','q','r', 's', 't', 'v', 'w', 'x','y','z']):
con+=1
file.close()
print("The total numbers of Vowels in the file:", vow)
print("The total numbers of Consonants in the file:", con)
print("The total numbers of Lower_case_letters in the file:", low)
print("The total numbers of Upper_case_letters s in the file:", up)
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
13
SAMPLE OUTPUT:
Story.txt:
***************************************************************************************
14
EX.NO: 9
DATE:
AIM:
To Write a method Disp() in Python, to read the lines from poem.txt and display those
words which are less than 5 characters.
Source Code:
def Disp():
F=open("Poem.txt")
S=F.read()
W=S.split()
print("The follwoing words are less than 5 characters")
for i in W:
if len(i)<5:
print(i,end="")
F.close()
Disp()
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
Sample Output:
Poem.txt:
**********************************************************************************
15
EX.NO: 10
DATE:
To write a python program to read lines from a text file "Sample.txt" and copy those lines
into another file which are starting with an alphabet 'a' or 'A'.
SOURCE CODE:
F1=open("Story.txt",'r')
F2=open("New.txt",'w')
S=F1.readlines()
for i in S:
if i[0]=='A' or i[0]=='a':
F2.write(i)
print("Written Successfully")
F1.close()
F2.close()
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
SAMPLE OUTPUT:
Sample.txt:
New.txt:
16
EX.NO: 11
DATE:
CREATING A PYTHON PROGRAM TO CREATE AND SEARCH RECORDS IN
BINARY FILE
AIM:
To write a Python Program to Create a binary file with roll number and name. Search
for a given roll number and display the name, if not found display appropriate message.
SOURCE CODE:
import pickle
def Create():
F=open("Students.dat", 'ab')
opt='y'
while opt=='y':
Roll No=int(input('Enter roll number:'))
Name-input ("Enter Name:")
L=[Roll No, Name]
pickle.dump(L,F)
opt=input("Do you want to add another student detail (y/n):")
F.close()
def Search():
F=open("Students.dat", 'rb')
n=int(input("Enter Roll. No of student to search:"))
found-0
try:
while True:
S=pickle.load(F)
if s[0]==n:
print("The searched Roll. No is found and Details are:",S)
found=1
break
except:
F.close()
if found==0:
print("The Searched Roll. No is not found")
#Main Program
Create()
Search()
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
17
SAMPLE OUPUT:
*******************************************************************************************
18
EX.NO:12
DATE:
AIM:
To write a Python Program to Create a binary file with roll number, name, mark
and update/modify the mark for a given roll number.
SOURCE CODE:
import pickle
def Create():
F=open("Marks.dat", 'ab')
opt='y'
while opt'y':
Roll Nomint(input('Enter roll number:'))
Name=input("Enter Name:")
Mark=int(input("Enter Marks: "))
opt=input("Do you want to add another student detail (y/n):")
L=[Roll No, Name, Mark]
pickle.dump(L,F)
F.close()
def Update():
F=open("Marks.dat","rb+")
n=int(input("Enter Student Roll. No to modify marks:"))
found=0
try:
while True:
Pos=F.tell()
S=pickle.load(F)
if s[0]==no:
print("The searched Roll. No is found and Details are:",s)
s[2]=int(input("Enter New Mark to be update:"))
F.seek(Pos)
pickle.dump(S,F)
found=1
19
F.seek(Pos) #moving the file pointer again beginning of the current record.
print("Mark updated Successfully and Details are:",S)
break
except:
F.close()
if found-=0:
print("The Searched Roll.No is not found")
#Main Program
Create()
Update()
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
20
SAMPLE OUTPUT:
PYTHON PROGRAM EXECUTED OUTPUT:
**********************************************************************************
21
EX.NO: 13
DATE:
AIM:
To write a Python program Create a CSV file to store Empno, Name, Salary and search any Empno
and display Name, Salary and if not found display appropriate message.
SOURCE CODE:
import csv
def Create():
F=open ("Emp.csv", 'a', newline='')
W=csv.writer (F)
opt='y'
while opt=='y':
No=int (input("Enter Employee Number: "))
Name=input ("Enter Employee Name:")
Sal=float(input("Enter Employee Salary: "))
L= [No, Name, Sal]
W.writerow(L)
opt=input("Do you want to continue (y/n)?: ")
F.close()
22
if found==0:
print("The searched Employee number is not found")
F.close()
#Main Program
Create()
Search ()
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
23
SAMPLE OUTPUT:
******************************************************************************
24
EX.NO: 14
DATE:
AIM:
To write a Python program to implement Stack using a list data-structure, to perform
(i) To push an object containing Doc_ID and Doc_name of doctors who specialize
in "ENT" to the stack.
(ii) (ii) To Pop the objects from the stack and display them.
(iii)
(iv) (iii) To display the elements of the stack (after performing PUSH or POP)
SOURCE CODE:
def Push():
Doc_ID=int(input("Enter the Doctor ID:"))
Doc_Name=input("Enter the Name of the Doctor:")
Mob=int(input("Enter the Mobile Number of the Doctor:"))
Special=input("Enter the Specialization:")
if Special=='ENT':
Stack.append([Doc_ID,Doc_Name])
def Pop():
if Stack==[]:
print("Stack is empty")
else:
print("The deleted doctor detail is:",Stack.pop())
def Peek():
if Stack==[]:
print("Stack is empty")
top=len(Stack)-1
else:
print("The top of the stack is:",Stack[top])
def Disp():
if Stack==[]:
print("Stack is empty")
else:
top=len(Stack)-1
for i in range(top,-1,-1):
print(Stack[i])
25
Stack=[]
ch='y'
print("Performing Stack Operations Using List\n")
while ch=='y' or ch=='Y':
print()
print("1.PUSH")
print("2.POP")
print("3.PEEK")
print("4.Disp")
opt=int(input("Enter your choice:"))
if opt==1:
Push()
elif opt==2:
Pop()
elif opt==3:
Peek()
elif opt==4:
Disp()
else:
print("Invalid Choice, Try Again!!!")
ch=input("\nDo you want to Perform another operation(y/n):")
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
26
SAMPLE OUTPUT:
Python Program Executed Output:
27
****************************************************************************************
28
EX.NO: 15
DATE:
AIM:
To Write a program, with separate user-defined functions to perform the following
Operations:
(i) To Create a function Push(Stk,D) Where Stack is an empty list and D is Dictionary of Items.
from this Dictionary Push the keys (name of the student) into a stack, where
the corresponding value (marks) is greater than 70.
(ii) To Create a Function Pop(Stk) , where Stk is a Stack implemented by a list of student
names. The function returns the items deleted from the stack.
(iii) To display the elements of the stack (after performing PUSH or POP).
Source Code:
def Push(Stk,D):
for i in D:
if D[i]>70:
Stk.append(i)
def Pop(Stk):
if Stk==[]:
return "Stack is Empty"
else:
print("The deleted element is:",end='')
return Stk.pop()
def Disp():
if Stk==[]:
print("Stack is empty")
else:
top=len(Stk)-1
for i in range(top,-1,-1):
print(Stk[i])
ch='y'
D={}
Stk=[]
print("Performing Stack Operations Using Dictionary\n")
while ch=='y' or ch=='Y':
print()
print("1.PUSH")
print("2.POP")
print("3.Disp")
29
opt=int(input("Enter your choice:"))
if opt==1:
D['Anikha']=int(input("Enter the Mark of Anikha:"))
D['Swetha']=int(input("Enter the Mark of Swetha:"))
D['Kohit']=int(input("Enter the Mark of Kohit:"))
D['Venkat']=int(input("Enter the Mark of Venkat:"))
D['Jayanthi']=int(input("Enter the Mark of Jayanthi:"))
Push(Stk,D)
elif opt==2:
r=Pop(Stk)
print(r)
elif opt==3:
Disp()
opt=input("Do you want to perform another operation(y/n):")
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
30
Sample Output:
1.PUSH
2.POP
3.Disp
Enter your choice:1
Enter the Mark of Anikha: 80
Enter the Mark of Swetha: 90
Enter the Mark of Kohit: 85
Enter the Mark of Venkat: 95
Enter the Mark of Jayanthi: 98
Do you want to perform another operation(y/n): y
1.PUSH
2.POP
3.Disp
Enter your choice: 3
Jayanthi
Venkat
Kohit
Swetha
Anikha
Do you want to perform another operation(y/n): y
1.PUSH
2.POP
3.Disp
Enter your choice: 2
The deleted element is: Jayanthi
Do you want to perform another operation(y/n): n
*********************************************************************************
31
EX.NO: 16
DATE:
Source Code:
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
32
Sample Output:
*******************************************************************************************************
33
EX.NO: 17
DATE:
AIM:
SOURCE CODE:
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
34
SAMPLE OUTPUT:
***************************************************************************************************************************** *************************************************
35
EX.NO: 18
DATE:
To write a Python Program to integrate MYSQL with Python to search an Employee using
EMPID and display the record if present in already existing table EMP, if not display the
appropriate message.
SOURCE CODE:
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
SAMPLE OUTPUT:
Python Executed Program Output:
36
EX.NO: 19
DATE:
To write a Python Program to integrate MYSQL with Python to search an Employee using
EMPID and update the Salary of an employee if present in already existing table EMP, if
not display the appropriate message.
SOURCE CODE:
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
37
SAMPLE OUTPUT:
**************************************************************************************************************************************************
38
SQL COMMANDS EXERCISE - 1
Ex.No: 20
DATE:
AIM:
To write Queries for the following Questions based on the given table:
USE STUDENTS;
SHOW DATABASES;
(e) Write a Query to List all the tables that exists in the current database.
SHOW TABLES;
Output:
39
SQL COMMANDS EXERCISE - 2
Ex.No: 21
DATE:
AIM:
To write Queries for the following Questions based on the given table:
(a) Write a Query to insert all the rows of above table into Info table.
(b) Write a Query to display all the details of the Employees from the above table 'STU'.
Output:
40
(c) Write a query to Rollno, Name and Department of the students from STU table.
Output:
Output:
Output:
********************************************************************************************
41
Ex.No: 22 SQL COMMANDS EXERCISE - 3
DATE:
AIM:
To write Queries for the following Questions based on the given table:
Output:
(b) Write a Query to list name of the students whose ages are between 18 to 20.
Output:
42
(c) Write a Query to display the name of the students whose name is starting with 'A'.
Output:
(d) Write a query to list the names of those students whose name have second alphabet 'n' in their
names.
Output:
**********************************************************************************************************
43
Ex.No: 23 SQL COMMANDS EXERCISE - 4
DATE:
AIM:
To write Queries for the following Questions based on the given table:
(b) Write a Query to change the fess of Student to 170 whose Roll number is 1, if the existing fess
is less than 130.
Output(After Update):
44
(c) Write a Query to add a new column Area of type varchar in table STU.
Output:
(d) Write a Query to Display Name of all students whose Area Contains NULL.
Output:
(e) Write a Query to delete Area Column from the table STU.
Output:
Output:
*******************************************************************************************
45
Ex.No: 24 SQL COMMANDS EXERCISE - 5
DATE:
AIM:
To write Queries for the following Questions based on the given table:
TABLE: UNIFORM
TABLE: COST
(a) To Display the average price of all the Uniform of Raymond Company from table COST.
Output:
(b) To display details of all the Uniform in the Uniform table in descending order of Stock date.
Output:
46
(c) To Display max price and min price of each company.
Output:
(d) To display the company where the number of uniforms size is more than 2.
Output:
(e) To display the Ucode, Uname, Ucolor, Size and Company of tables uniform and cost.
Output:
*****************************************************************************************
47