[go: up one dir, main page]

0% found this document useful (0 votes)
26 views25 pages

Board Practical Source Code - 2024-2025

The document contains a series of Python programs demonstrating various functionalities including arithmetic operations, Fibonacci series, factorial calculation, mathematical functions, random number generation, file handling, and employee record management. Each section outlines the aim, source code, results, and output of the respective program. The programs are designed to be executed successfully, showcasing basic to advanced Python programming concepts.

Uploaded by

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

Board Practical Source Code - 2024-2025

The document contains a series of Python programs demonstrating various functionalities including arithmetic operations, Fibonacci series, factorial calculation, mathematical functions, random number generation, file handling, and employee record management. Each section outlines the aim, source code, results, and output of the respective program. The programs are designed to be executed successfully, showcasing basic to advanced Python programming concepts.

Uploaded by

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

1. CREATING A MENU DRIVEN PROGRAM TO PERFORM ARITHMETIC OPERATIONS.

AIM:
To write a menu driven Python Program to perform Arithmetic operations (+,-*, /) Based
on the user’s choice
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.
OUTPUT :
========================= RESTART: C:/Users/user26/1.py
========================
Enter the first value :10
Enter the second value :20
Enter any one of the operator (+,-,*,/,//,%)+
The result is: 30.0
========================= RESTART: C:/Users/user26/1.py
========================
Enter the first value :25
Enter the second value :12
Enter any one of the operator (+,-,*,/,//,%)//
The result is: 2.0
2. CREATING A PYTHON PROGRAM TO DISPLAY FIBONACCI SERIES
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.

OUTPUT :
=================== RESTART: C:/Users/user6/python.py ==================
How many Fibonacci numbers you want to display?5
0
1
1
2
3

3. CREATING A MENU DRIVEN PROGRAM TO FIND FACTORIAL AND SUM OF LIST OF


NUMBERS USING FUNCTION.
AIM:
To write a menu driven Python Program to find Factorial and sum of list of numbers using
function
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)

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.

OUTPUT :
========================= RESTART: C:/Users/user26/1.py
========================
Enter a Number: 5
Factorial of 5 is: 120
========================= RESTART: C:/Users/user26/1.py
========================
Enter list items: 2,3,4,5
Sum of list items is: 14

4. CREATING A PYTHON PROGRAM TO IMPLEMENT RETURNING VALUE(S) FROM


FUNCTION
AIM:
To Write a Python program to define the function Check(no1,no2) that takes two numbers
and Returns the number that has the minimum one's digit.

SOURCE CODE :
def check(n1, n2):
if n1%10 < n2%10:
return n1
else:
return n2
a = int(input("Enter first Number: "))
b = int(input("Enter Second Number: "))
r = check(a,b)
print("The number that has minimum one's digit is", r)

RESULT :
Thus, the above Python program has been executed and the output is verified successfully.

OUTPUT :
=================== RESTART: C:/Users/user6/pythonprog.py ==================
Enter first Number: 245
Enter Second Number: 456
The number that has minimum one's digit is 245
5. CREATING A PYTHON PROGRAM TO IMPLEMENT MATHEMATICAL FUNCTIONS
AIM:
To write a Python program to implement python mathematical functions to find:
(i) To find Square of a Number.
(ii) To find Log of a Number(i.e. Log10)
(iii) To find Quad of a Number

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.

OUTPUT :
=================== RESTART: C:/Users/user6/python.py ==================
The Square of a Number is: 25.0
The Log of a Number is: 1.0
The Quad of a Number is: 5.385164807134504

6. CREATING A PYTHON PROGRAM TO GENERATE RANDOM NUMBER BETWEEN 1 TO 6


AIM:
To write a Python program to generate random numbers between 1 to 6 to simulate the
dice.
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.

OUTPUT :
========================= RESTART: C:/Users/user26/1.py
========================
Do you want to roll the dice (y/n): y
Your Number is: 3
Do you want to roll the dice (y/n): y
Your Number is: 3
Do you want to roll the dice (y/n): y
Your Number is: 1
Do you want to roll the dice (y/n): y
Your Number is: 3
Do you want to roll the dice (y/n): n

7. CREATING A PYTHON PROGRAM TO READ A TEXT FILE LINE BY LINE AND DISPLAY
EACH WORD SEPARATED BY '#'.
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.

OUTPUT :
========================= RESTART: C:/Users/user26/1.py
========================
The# sunset# hangs# on# a# cloud#.
8. CREATING A PYTHON PROGRAM TO READ A TEXT FILE AND DISPLAY THE NUMBER
OF VOWELS/CONSONANTS/LOWER CASE/ UPPER CASE CHARACTERS.
AIM:
To write a Python Program to read a text file "Story.txt" and display the number of Vowels/
Consonants/ Lowercase / Uppercase/characters in the file.

SOURCE CODE :
file=open(r"C:\Users\user\Desktop\python.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.

OUTPUT :
=================== RESTART: C:/Users/user6/binary.py ==================
The total numbers of Vowels in the file: 20
The total numbers of Consonants in the file: 27
The total numbers of Lower_case_letters in the file: 46
The total numbers of Upper_case_letters s in the file: 3
9. CREATING PYTHON PROGRAM TO DISPLAY SHORT WORDS FROM A TEXT FILE
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(r"D:\Name.txt","r")
S=F.read()
W=S.split()
print("The following 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.

OUTPUT :
========================= RESTART: C:/Users/user26/1.py
========================
The following words are less than 5 characters
rays of on the sky

10. CREATING A PYTHON PROGRAM TO COPY PARTICULAR LINES OF A TEXT FILE


INTO ANOTHER TEXT FILE

AIM:
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(r"D:\Name.txt","r")
F2=open(r"D:\Name1.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.

OUTPUT :
========================= RESTART: C:/Users/user26/1.py
========================
Aeroplane was invented by the Wright brothers.
An apple a day keeps the doctor away.

11. CREATING A PYTHON PROGRAM TO CREATE AND SEARCH RECORDS IN BINARY


FILES.

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(r"D:\Name.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(r"D:\Name.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")
Create()
Search()

RESULT :
Thus, the above Python program has been executed and the output is verified successfully.

OUTPUT :
========================= RESTART: C:/Users/user26/1.py
========================
Enter roll number:1
Enter Name:Venkat
Do you want to add another student detail (y/n):y
Enter roll number:2
Enter Name:Anikha
Do you want to add another student detail (y/n):n
Enter Roll. No of student to search:1
The searched Roll. No is found and Details are: [1, 'Venkat']
12. CREATING A PYTHON PROGRAM TO CREATE AND UPDATE/MODIFY RECORDS IN
BINARY FILE

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(r"D:\Name.dat", 'ab')
opt='y'
while opt=='y':
Roll_No=int(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(r"D:\Name.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]==n:
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
f.seek(Pos) #moving the file pointer again at the 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")
Create()
Update()

RESULT :
Thus, the above Python program has been executed and the output is verified successfully.

OUTPUT :
================================= RESTART: C:/Users/user26/ds.py ========
Enter roll number:1
Enter Name:Venkat
Enter Marks: 90
Do you want to add another student detail (y/n):y
Enter roll number:2
Enter Name:Anikha
Enter Marks: 89
Do you want to add another student detail (y/n):n
Enter Student Roll. No to modify marks:2
The searched Roll. No is found and Details are: [2, 'Anikha', 89]
Enter New Mark to be update:100
Mark updated Successfully and Details are: [2, 'Anikha', 100]
13. CREATING A PYTHON PROGRAM TO CREATE AND SEARCH EMPLOYEE’S RECORD
IN CSV FILE.

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 (r"D:\Name.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()
def Search ():
f=open(r"D:\Name.csv ", 'r',newline='\r\n')
n=int(input("Enter Employee number to search"))
found=0
row=csv.reader(f)
for data in row:
if data[0]==str(n):
print("\nEmployee Details are: ")
print("=========================")
print("Name:",data[1])
print("Salary: ",data[2])
print("=========================")
found=1
break
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.

OUTPUT :
================================ RESTART:
C:/Users/user26/ds.py====================
Enter Employee Number: 1
Enter Employee Name:Anikha
Enter Employee Salary: 100000
Do you want to continue (y/n)?: y
Enter Employee Number: 2
Enter Employee Name:Kohit
Enter Employee Salary: 150000
Do you want to continue (y/n)?: y
Enter Employee Number: 3
Enter Employee Name:Swetha
Enter Employee Salary: 200000
Do you want to continue (y/n)?: n
Enter Employee number to search1
Employee Details are:
=========================
Name: Anikha
Salary: 100000.0
=========================
14. CREATING A PYTHON PROGRAM TO IMPLEMENT STACK OPERATIONS(LIST)
AIM:
To write a Python program to implement Stack using a list data-structure, to perform the
following operations:
(i) To push an object containing Doc_ID and Doc_name of doctors who specialize in "ENT" to the
stack. (ii) To Pop the objects from the stack and display them.
(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")
else:
top=len(Stack)-1
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])
Stack=[]
ch='y'
print("Performing Stack Operations Using List\n")
while ch=='y' or ch=='Y':
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.

OUTPUT :
Performing Stack Operations Using List

1.PUSH
2.POP
3.PEEK
4.Disp
Enter your choice:1
Enter the Doctor ID:00043
Enter the Name of the Doctor:Venkat
Enter the Mobile Number of the Doctor:96260
Enter the Specialization:ENT

Do you want to Perform another operation(y/n):y


1.PUSH
2.POP
3.PEEK
4.Disp
Enter your choice:1
Enter the Doctor ID:00256
Enter the Name of the Doctor:Anikha
Enter the Mobile Number of the Doctor:74315
Enter the Specialization:ENT

Do you want to Perform another operation(y/n):y


1.PUSH
2.POP
3.PEEK
4.Disp

Enter your choice:1


Enter the Doctor ID:00827
Enter the Name of the Doctor:Jayanthi
Enter the Mobile Number of the Doctor:93610
Enter the Specialization:Cardio

Do you want to Perform another operation(y/n):y


1.PUSH
2.POP
3.PEEK
4.Disp
Enter your choice:4
[256, 'Anikha']
[43, 'Venkat']

Do you want to Perform another operation(y/n):y


1.PUSH
2.POP
3.PEEK
4.Disp
Enter your choice:3
The top of the stack is: [256, 'Anikha']

Do you want to Perform another operation(y/n):y


1.PUSH
2.POP
3.PEEK
4.Disp
Enter your choice:2
The deleted doctor detail is: [256, 'Anikha']
Do you want to Perform another operation(y/n):y
1.PUSH
2.POP
3.PEEK
4.Disp
Enter your choice:4
[43, 'Venkat']

Do you want to Perform another operation(y/n):n

15. CREATING A PYTHON PROGRAM TO IMPLEMENT STACK OPERATIONS


(DICTIONARY).

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")
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.

OUTPUT :
================================ RESTART:
C:/Users/user26/ds.py===================
Performing Stack Operations Using Dictionary

1.PUSH
2.POP
3.Disp
Enter your choice:1
Enter the Mark of Anikha:100
Enter the Mark of Swetha:98
Enter the Mark of Kohit:95
Enter the Mark of Venkat:90
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:2
The deleted element is:Jayanthi
Do you want to perform another operation(y/n):n

1.PUSH
2.POP
3.Disp
Enter your choice:3
Venkat
Kohit
Swetha
Anikha
Do you want to perform another operation(y/n):n

SQL COMMAND - III

a) Write a Query to delete the details of Roll number 8.

DELETE FROM STU WHERE ROLLNO=8;

b) Write a Query to change the fees of Student to 170 whose Roll number is 1, if the existing
fees is less than 130.

UPDATE STU SET FEES=170 WHERE ROLLNO=1 AND FEES<130;

c) Write a Query to add a new column Area of type varchar in table STU.

ALTER TABLE STU ADD AREA VARCHAR(20);

d) Write a Query to delete table from Database.

DROP TABLE STU;


SQL COMMAND - IV

a) Write a Query to list name of female students in Hindi Department

SELECT NAME FROM STU WHERE DEPT='HINDI' AND GENDER='F';

b) Write a Query to display the name of the students whose name is starting with 'A'.

SELECT NAME FROM STU WHERE NAME LIKE 'A%';

c) Write a Query to list name of the students whose ages are between 18 to 20.

SELECT NAME FROM STU WHERE AGE BETWEEN 18 AND 20;

d) Write a query to list the names of those students whose name have the second alphabet
'n' in their names.

SELECT NAME FROM STU WHERE NAME LIKE '_N%';

You might also like