0% found this document useful (0 votes)
29 views

Practical File XII CS 2024-25

Cs
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)
29 views

Practical File XII CS 2024-25

Cs
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/ 22

S PA Scottish School

ASPAM
Scottish School
EDUCATE TO EMPOWER

COMPUTER SCIENCE
PYTHON
XII

Board Roll No. _____________________________________


COMPUTER SCIENCE [PYTHON]
XII

PRACTICAL FILE
ON
PYTHON PROGRAMS
&
MY SQL

BOARD ROLL NO. _______________________________________________________________

SUBMITTED BY : _______________________________________________________
ACKNOWLEDGEMENT

I would like to express my special thanks of gratitude towards my teacher

…………………………………………….for their able guidance and support in

completing my Practical File.

I would also like to extend my gratitude to my Principal for providing me

with all the facilities that was required to complete this Practical File.

Yours sincerely,

_________________________
CERTIFICATE

This is to certify that __________________________________________ of Grade XII, has

successfully completed this Practical File Report for Computer Science Practical

Examination of the Central Board of Secondary Education in the Session 2024-

2025. This project is the result of his/her efforts and endeavors. It is further

certified that he/she has prepared the project under my guidance.

____________________________________ __________________________________
Internal Examiner External Examiner

Principal
INDEX

S.No Description of Assignment


Program to enter two numbers and print the arithmetic operations
1 like +,-,*, /, // and %.

2 Write a python program to apply string functions to change case.


Write a python program using function to pass list to a function and
3 double the odd values and half even values of a list and display
list element after changing.
Write a Python program input n numbers in tuple and count how
4 many even and odd numbers are entered.
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*******
5
1. Delete from Dictionary
2. Search Phone number using name from Dictionary
3. Exit

Write a STRING menu driven program in python to do following


MENU

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

Q2. Write a python program to apply string functions to change case.


Ans:
# Python3 program to show the
# working of upper() function
text = 'geeKs For geEkS'

# upper() function to convert


# string to upper case
print("\nConverted String:")
print(text.upper())

# lower() function to convert


# string to lower case
print("\nConverted String:")
print(text.lower())

# converts the first character to


# upper case and rest to lower case
print("\nConverted String:")
print(text.title())

# swaps the case of all characters in the string


# upper case character to lowercase and viceversa
print("\nConverted String:")
print(text.swapcase())

# convert the first character of a string to uppercase


print("\nConverted String:")
print(text.capitalize())

# original string never changes


print("\nOriginal String")
print(text)

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=[ ]

S = int(input("Please Enter the Total Number of Elements : "))


for i in range(S):
value = int(input("Please enter the %d Element of List1 : " %i))
l.append(value)
numbers=tuple(l)
count_odd = 0
count_even = 0
for x in numbers:
if not x % 2:
count_even+=1
else:
count_odd+=1
print("Number of even numbers :",count_even)
print("Number of odd numbers :",count_odd)

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

Enter your choice:1


Enter total number of friends:2
enter name :APARNA
enter phone number:7083190774
{'APARNA': 7083190774}
---------------------------------
enter name :ARCHANA
enter phone number:9878390928
{'APARNA': 7083190774, 'ARCHANA': 9878390928}
---------------------------------
Enter name to delete:ARCHANA
Phonebook Information
---------------------
Name Phone number
APARNA 7083190774
******MENU\*******n
1:Delete from Dictionary
2:Search Phone number using name from Dictionary
3:Exit
Enter your choice:2
Enter name to search:APARNA
Phone number= 7083190774
******MENU\*******n
1:Delete from Dictionary
2:Search Phone number using name from Dictionary
3:Exit

Enter your choice:3

Q6: Write a menu driven program in python to do following


MENU
1. Reverse String
2. Check Whether string is Palindrome
3. Make half string in Uppercase
4. Exit
Ans:

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

Enter your choice:1


Enter String:abc
cba
******MENU\*******n
1:Reverse String
2:Check whether string is palindrome
3:Make half string in Uppercase
4:Exit

Enter your choice:2


Enter String:madam
This string is palindrome
******MENU\*******n
1:Reverse String
2:Check whether string is palindrome
3:Make half string in Uppercase
4:Exit
Enter your choice:3
Enter String:aparna
The original string is : aparna
The resultant string : apaRNA
******MENU\*******n
1:Reverse String
2:Check whether string is palindrome
3:Make half string in Uppercase
4:Exit

Enter your choice:4


>>>

Q7: 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.
Ans:

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

Q8: Write a Python program to remove duplicates from a list.


Ans:
a=[]
n=int(input('how many elements u want in list:'))
for i in range(0,n):
n1=int(input('enter item in list:'))
a.append(n1)
print('Original list is:',a)
print('List after removing duplicate elements:')
dup_items = set()
uniq_items = []
for x in a:
if x not in dup_items:
uniq_items.append(x)
dup_items.add(x)
print(dup_items)
OR
print(set(l))
OR
Print(list(set(l))) # convert into list

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

# Check if n is present at mid


if list1[mid] < n:
low = mid + 1
# If n is greater, compare to the right of mid
elif list1[mid] > n:
high = mid - 1
# If n is smaller, compared to the left of mid
else:
return mid

# element was not present in the list, return -1


return -1

# 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

Q10. Write a menu driven program to generate random numbers given in


specific range and to display calendar after giving month and year.
MENU
1. Generate Random numbers
2. Calender of a month
3.Exit
Code:
# Program to display calendar of the given month and year

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*******

1:Random Number generators


2:Calender of a month
3:Exit

Enter your choice:1


[39, 21, 21, 29, 22, 36, 33, 32, 20, 31]
******MENU*******

1:Random Number generators


2:Calender of a month
3:Exit

Enter your choice:2


Enter year: 2021
Enter month: 7
July 2021
Mo Tu We Th Fr Sa Su
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

******MENU*******

1:Random Number generators


2:Calender of a month
3:Exit

Enter your choice:3


>>>

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

 Computer Science in PYTHON by Preeti Arora

________________________________________

You might also like