Practical File XII CS 2024-25
Practical File XII CS 2024-25
ASPAM
Scottish School
EDUCATE TO EMPOWER
COMPUTER SCIENCE
PYTHON
XII
PRACTICAL FILE
ON
PYTHON PROGRAMS
&
MY SQL
SUBMITTED BY : _______________________________________________________
ACKNOWLEDGEMENT
with all the facilities that was required to complete this Practical File.
Yours sincerely,
_________________________
CERTIFICATE
successfully completed this Practical File Report for Computer Science Practical
2025. This project is the result of his/her efforts and endeavors. It is further
____________________________________ __________________________________
Internal Examiner External Examiner
Principal
INDEX
6 1. Reverse String
2. Check Whether string is Palindrome
3. Make half string in Uppercase
4. Exit
7 Write a program to read a list of n integers (positive as well as
negative). Create two new lists, one having all positive numbers
with sum and the other having all negative numbers with sum from
the given list.
8 Write a Python program to remove duplicates from a list.
Write a python code using function to search an element in a list
9
using Binary search method.
Write a menu driven program to generate random numbers given in
specific range and to display calendar after giving month and year.
MENU
10
1. Generate Random numbers
2. Calender of a month
3.Exit
Write a python program to read and display file content line by line
11
with each word separated by #.
Write a python program Read a text file and display the number of
12
vowels/consonants/uppercase/lowercase alphabets in the file.
Program to store multiple integers in a binary file and read display it
13
on screen DATA FILE HANDLING
14 Program to copy content of one file to another file Data File Handling.
Program to capitalize the first letter of sequence in a file Data File
15
Handling
A menu driven program to perform read and write operation using a
16 text file containing student information using function DATA
HANDLING FILE
Program to print a record from table in a database at run time—
17
PYTHON-MYSQL CONNECTION
Program to print a record from table up to a certain limit PYTHON-
18
MYSQL CONNECTION
Program to insert record in a table —PYTHON - MYSQL
19
CONNECTION.
A menu driven program to perform all function on a table ‘student’---
20
PYTHON-MYSQL CONNECTION.
Q1: Program to input two numbers and performing all arithmetic operations
#Input first number
num1 = int(input("Enter first number: "))
#Input Second number
num2 = int(input("Enter second number: "))
#Printing the result for all arithmetic operations
print("Results:-")
print("Addition: ",num1+num2)
print("Subtraction: ",num1-num2)
print("Multiplication: ",num1*num2)
print("Division: ",num1/num2)
print("Modulus: ", num1%num2)
print("Floor Division: ",num1//num2)
print("Exponentiation: ",num1 ** num2)
OUTPUT:
Enter first number: 8
Enter second number: 3
Results:-
Addition: 11
Subtraction: 5
Multiplication: 24
Division: 2.6666666666666665
Modulus: 2
Floor Division: 2
Exponentiation: 512
Output is:
Converted String:
GEEKS FOR GEEKS
Converted String:
geeks for geeks
Converted String:
Geeks For Geeks
Converted String:
GEEkS fOR GEeKs
Original String
geeKs For geEkS
Q3. Write a python program using function to pass list to a function and
double the odd values and half even values of a list and display list element
after changing.
Ans:
def splitevenodd(A):
evenlist = []
oddlist = []
for i in A:
if (i % 2 == 0):
evenlist.append(i//2)
else:
oddlist.append(i*i)
print("Even lists:", evenlist)
print("Odd lists:", oddlist)
A=list()
n=int(input("Enter the size of the List ::"))
print("Enter the Elements of List ::")
for i in range(int(n)):
k=int(input(""))
A.append(k)
splitevenodd(A)
Output is:
Enter the size of List ::5
Enter the Elements of List ::
12
3
14
5
1
Even lists: [6, 7]
Odd lists: [9, 25, 1]
Q4. Write a Python program input n numbers in tuple and count how many
even and odd numbers are entered.
Ans:
l=[ ]
Output is:
Please Enter the Total Number of Elements : 5
Please enter the 0 Element of List1 : 34
Please enter the 1 Element of List1 : 3
Please enter the 2 Element of List1 : 2
Please enter the 3 Element of List1 : 56
Please enter the 4 Element of List1 : 3
Number of even numbers : 3
Number of odd numbers : 2
Q5. Write a menu driven program in python to delete name of a student from
dictionary and to search phone no of a student by student name. Create
menu as below:
MENU
1. Delete from Dictionary
2. Search Phone number using name from Dictionary
3. Exit
Ans:
phonebook=dict()
while True:
print("******MENU\*******n")
print('1:Delete from Dictionary')
print('2:Search Phone number using name from Dictionary')
print('3:Exit\n')
ch=int(input('Enter your choice:'))
if ch==1:
n=int(input("Enter total number of friends:"))
i=1
while(i<=n):
a=input("enter name :")
b=int(input("enter phone number:"))
phonebook[a]=b
i=i+1
print(phonebook)
print('---------------------------------')
name=input("Enter name to delete:")
del phonebook[name]
k=phonebook.keys()
print("Phonebook Information")
print('---------------------')
print("Name",'\t',"Phone number")
for i in k:
print(i,'\t',phonebook[i])
if ch==2:
name=input("Enter name to search:")
f=0
k=phonebook.keys()
for i in k:
if(i==name):
print("Phone number= ",phonebook[i])
f=1
if (f==0):
print("Given name not exist")
if ch==3:
break
Output is:
******MENU\*******n
1:Delete from Dictionary
2:Search Phone number using name from Dictionary
3:Exit
while True:
print("******MENU*******\n")
print('1:Reverse String')
print('2:Check whether string is palindrome')
print('3:Make half string in Uppercase')
print('4:Exit\n')
ch=int(input('Enter your choice:'))
if ch==1:
st = input('Enter String:')
print(st[::-1])
if ch==2:
st = input('Enter String:')
if st==st[::-1]:
print('This string is palindrome')
else:
print('String is not palindrome')
if ch==3:
st = input('Enter String:')
print("The original string is : " + str(st))
# computing half index
hlf_idx = len(st) // 2
res = ''
for idx in range(len(st)):
# uppercasing later half
if idx >= hlf_idx:
res += st[idx].upper()
else :
res += st[idx]
# printing result
print("The resultant string : " + str(res))
if ch==4:
break
Output is:
******MENU*******
1:Reverse String
2:Check whether string is palindrome
3:Make half string in Uppercase
4:Exit
list1=[]
plist1=[]
nlist1=[]
sum=0
sum1=0
n=int(input('how many elements u want in list:'))
for i in range(0,n):
a=int(input('enter item in list:'))
list1.append(a)
print('Original list is:',list1)
for i in range(0,n):
if list1[i]<0:
nlist1.append(list1[i])
sum=sum+list1[i]
else:
plist1.append(list1[i])
sum1=sum1+list1[i]
print('positive list is;',plist1)
print('sum of +ve numbers:',sum1)
print('Negative list is;',nlist1)
print('sum of -ve numbers:',sum)
Output is:
how many elements u want in list:4
enter item in list:3
enter item in list:2
enter item in list:-1
enter item in list:-1
Original list is: [3, 2, -1, -1]
positive list is; [3, 2]
sum of +ve numbers: 5
Negative list is; [-1, -1]
sum of -ve numbers: -2
Output is:
how many elements u want in list:5
enter item in list:34
enter item in list:2
enter item in list:34
enter item in list:2
enter item in list:1
Original list is: [34, 2, 34, 2, 1]
List after removing duplicate elements:
{1, 34, 2}
Q9: Write a python code using function to search an element in a list using
Binary search method.
Code:
def binary_search(list1, n):
low = 0
high = len(list1) - 1
mid = 0
while low <= high:
# for get integer result
mid = (high + low) // 2
# Initial list1
list1=[]
y=int(input('how many elements u want in list:'))
for i in range(0,y):
n1=int(input('enter item in ascending/descending order in list:'))
list1.append(n1)
x=(int(input('Enter item to search:')))
# Function call
result = binary_search(list1, x)
if result != -1:
print("Element is present at index", str(result),'and at position:',str(result+1))
else:
print("Element is not present in list1")
Output is:
how many elements u want in list:5
enter item in ascending/descending order in list:20
enter item in ascending/descending order in list:15
enter item in ascending/descending order in list:14
enter item in ascending/descending order in list:13
enter item in ascending/descending order in list:12
Enter item to search:14
Element is present at index 2 and at position: 3
import random
import calendar
while True:
print("******MENU*******\n")
print('1:Random Number generators')
print('2:Calender of a month')
print('3:Exit\n')
ch=int(input('Enter your choice:'))
if ch==1:
num = 10
start = 20
end = 40
res = []
for j in range(num):
res.append(random.randint(start, end))
print(res)
if ch==2:
yy = int(input("Enter year: "))
mm = int(input("Enter month: "))
print(calendar.month(yy, mm))
if ch==3:
break
Output is:
******MENU*******
******MENU*******
Q 11:Write a python program to read and display file content line by line
with each word separated by #.
Code:
file=input('Enter the file: ')
f =open( file,'r')
item=[]
for line in f:
words=line.split()
for i in words:
item.append(i)
print('#'.join(item))
Output is:
Enter the file: i.txt
i#like#india
Q 12:Write a python program Read a text file and display the number of
vowels/consonants/uppercase/lowercase characters in the file.
Code:
def cnt():
f=open('i.txt','r')
cont=f.read()
v=0
c=0
lcl=0
ucl=0
for ch in cont:
if(ch.islower()):
lcl=lcl+1
elif (ch.isupper()):
ucl=ucl+1
if (ch in['a','e','i','o','u'] or ch in['A','E','I','O','U']):
v=v+1
elif (ch in ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y',
'z'] or ch in['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W','X',
'Y','Z']):
c=c+1
f.close()
print('Vowels are:',v)
print('Consonents are:',c)
print('Lowercase letters are:',lcl)
print('Uppercase letters are:',ucl)
cnt()
Output is:
Vowels are: 6
Consonents are: 4
Lowercase letters are: 10
Uppercase letters are: 0
BIBLIOGRAPHY
www.w3resource.com
www.codescracker.com
www.geeksforgeeks.org
www.programiz.com
www.bbbeginners.com
Text Books :
Computer Science in PYTHON by Sumita Arora
________________________________________