0% found this document useful (0 votes)
38 views7 pages

Python Practical Programs for XII Class

The document outlines a series of Python practical exercises for the academic year 2025-2026, focusing on various programming concepts such as functions, data structures, file handling, and database connectivity. Each exercise includes specific tasks, such as manipulating dictionaries, implementing stack operations, and interacting with MySQL databases. The exercises aim to enhance students' programming skills through practical applications and problem-solving scenarios.

Uploaded by

vellankividwat
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)
38 views7 pages

Python Practical Programs for XII Class

The document outlines a series of Python practical exercises for the academic year 2025-2026, focusing on various programming concepts such as functions, data structures, file handling, and database connectivity. Each exercise includes specific tasks, such as manipulating dictionaries, implementing stack operations, and interacting with MySQL databases. The exercises aim to enhance students' programming skills through practical applications and problem-solving scenarios.

Uploaded by

vellankividwat
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

XII CLASS PYTHON PRACTICAL RECORD PROGRAMS

2025-2026

1. Write a function dispBook(BOOKS) in Python, that takes a dictionary Books as an


argument and displays the names in uppercase of those books whose name starts with a
consonant.

For example, Consider the following dictionary


BOOKS={1: "Python", 2: "Internet Fundamentals ", 3: "Networking ", 4: "Oracle sets ", 5:
"Understanding HTML"}

The output should be:


PYTHON
NETWORKING

2. Write a user defined function in Python named showGrades(S) which takes the
dictionary S as an argument. The dictionary, S contains Name: [Eng, Math, Science] as
key: value pairs. The function displays the corresponding grade obtained by the students
according to the following grading rules.

Average of Eng, Math, Science Grade


>=90 A
<90 but >=60 B
<60 C

For example: Consider the following dictionary

S=,“AMIT”:*92,86,64+, “NAGMA”:*65,42,43+, “DAVID”:*92,90,88+-


The output should be:
AMIT – B
NAGMA – C
DAVID – A

3. Write a user defined function in Python named Puzzle(W,N) which takes the argument
W as an English word and N as an integer and returns the string where every Nth
Alphabet of the word W is replaced with an underscore (“_”).

For example: if w contains the “TEKEVISION” and N is 3, then the function should return
the string “TE_EV_SI_N”. Likewise for the word “TELEVISION” if N is 4, then the function
should return “TEL_VIS_ON”.
Page 1 of 7
4. Write a Python Program containing a function FindWord(STRING, SEARCH), that
accepts two arguments: STRING and SEARCH, and prints the count of occurrence of
SEARCH in STRING.

Write appropriate statements to call the function.

For example, if STRING = "Learning history helps to know about history with interest in
history" and SEARCH = 'history',
the function should display: The word history occurs 3 times.

5. Write a Python menu driven program with Push ( ), Pop ( ), Peek( ), Display( ) functions
to implement a stack using a list.

6. A list contains following record of customer: [Customer_name, Room Type]


Write the following user defined functions to perform given operations on the stack
names ‘Hotel’:
(i) Push_Cust( ) - To Push customer’s names of those customers who are staying in
‘Delux’ Room Type.

(ii) Pop_Cust( ) - To Pop the names of customers from the stack and display them. Also,
display “Underflow” when there are no customers in the stack.
For example:
If the lists with customer details are as follows:
["Siddharth", "Delux"]
["Rahul", "Standard"]
["Jerry", "Delux"]

The stack should contain:


Jerry
Siddharth

The output should be:


Jerry
Siddharth
Underflow

7. Write the definition of a user defined function Push3_5(N) which accepts a list of
integers in a parameter N and pushes all those integers which are divisible by 3 or
divisible by 5 from the list N into a list named Only3_5.
Page 2 of 7
Write a program in Python to input 5 integers into a list named NUM. The program
should then use the function Push3_5 ( ) to create the stack of the list Only3_5.
Thereafter pop each integer from the list Only3_5 and display the popped value. When
the list is empty, display the message "StackEmpty".

For example:
If the integers input into the list NUM are : [ 10, 6, 14, 18, 30]
Then the stack Only3_5 should store : [10, 6, 18,30]
And the output should be displayed as 30 18 6 10 StackEmpty

8. Given a Dictionary Stu_dict containing marks of students for three test-series in the
form Stu_ID:(TS1, TS2, TS3) as key-value pairs.

Write a Python program with the following user-defined functions to perform the
specified operations on a stack named Stu_Stk.

(i) Push_elements(Stu_Stk, Stu_dict) : It allows pushing IDs of those students, from the
dictionary Stu_dict into the stack Stu_Stk, who have scored more than or equal to 80
marks in the TS3 Test.

(ii) Pop_elements(Stu_Stk): It removes all elements present inside the stack in LIFO order
and prints them. Also, the function displays ‘Stack Empty’ when there are no elements in
the stack.
Call both functions to execute queries.
For example:
If the dictionary Stu_dict contains the following date:
Stu_dict = {5:(87,68,89), 10:(57,54,61), 12:(71,67,90), 14:(66,81,80), 18:(80,48,91)}

After executing Push_elements( ), Stk_ID should contain [5,12,14,18]

After executing Pop_elements(), The output should be:


18
14
12
5
Stack Empty

9. Raju wants to write a code in Python for the following:


Consider the following to establish connectivity between Python and MySQl:
Username: root, Password: airplane, Host: localhost

Page 3 of 7
(i) To create a database school
(ii) To show the databases
(iii) To create a customer table
Table: Customer
Field Name Data Type
Mobile_No varchar(10)
Email Id Varchar(50)
Name varchar(32)
Age int
Address varchar(100)

(iv) To show the tables


(v) To describe customer table structure
(vi) To insert two records into the customer table
(vii) To display the record from the customer table for the given Mobile_No by using with
% formatting pattern
(viii) To delete the record from the customer table for the given Mobile_No by using with
{}.format pattern

10. Sumit wants to write a code in Python to display all the details of the passengers from
the table flight in MySQL database, Travel. The table contains the following attributes:
F_code: Flight code (String)
F_name: Name of flight (String)
Source: Departure city of flight (String)
Destination: Destination city of flight (String)

Consider the following to establish connectivity between Python and MySQl:


Username: root, Password: airplane, Host: localhost

11. Write a function display_words() in Python to read lines from a text file "[Link]",
and display those words, which are less than 4 characters.

12. Write a program to read a text file “[Link]” and display the number of vowels /
consonants / uppercase / lowercase characters / digits / spaces in the file.

13. Write a function in Python to read a text file ‘[Link]’ and displays those lines which
begin with the word ‘You’.

Page 4 of 7
14. Write a user defined function in Python named showInLines( ) which reads contents
of a text file names [Link] and displays every sentence in a separate line.

Assume that a sentence ends with a full stop (.), a question mark (?) or an exclamation
mark (!).

For example, if the content of the file [Link] is as follows:

Our parents told us that we must eat vegetables to healthy. And it turns out, our parents
were right! So, what else did our parents tell?

Then the function should display the files’s content as follows:

Our parents told us that we must eat vegetables to healthy.

And it turns out, our parents were right!

So, what else did our parents tell?

15. Consider a file, [Link], containing records of the following structure:


[SportName, TeamName, No_Players]

Write a function, copyData(), that reads contents from the file [Link] and copies the
records with Sport name as “Basket Ball” to the file names [Link]. The function
should return the total number of records copied to the file [Link].

16. A binary file, [Link] has the following structure:


[Emp_Id, Name, Salary]
Where Emp_Id : Employee id
Name: Employee Name
Salary: Employee Salary
Write a user defined function, disp_Details(), that would read the contents of the file
[Link] and display the details of those employees whose salary is below 25000.

17. Consider a binary file, [Link], containing records stored in the given format:
{item_id: [item_name, amount]}

Write a function, Copy_new(), that copies all records whose amount is greater than 1000
from [Link] to new_items.dat.
Page 5 of 7
18. Consider a Binary file [Link] containing a dictionary having multiple elements.
Each element is in the form BNO: [BNAME, BTYPE, PRICE] as key:value pair
where
BNO- Book Number
BNAME- Book Name
BTYPE- Book Type
PRICE- Book Price
Write a user defined function, findBook(price), that accepts price as parameter and
displays all those records from the binary file [Link] which has a book price more
than or equal to the price value passed as a parameter.

19. Write a program in python that defines and calls the following user defined functions:

a) Add( ): To accept and add data of a furniture to a CSV file ‘[Link]’. Each record
consists of a list with field element as fid, fname and fprice to store furniture id, furniture
name and furniture price respectively.

b) Search( ): To display the records of the furniture whose price is more than 10000.

20. Vedansh is a Python programmer working in a school. For the Annual Sports Event,
he has created a csv file named [Link], to store the results of students in different
sports events. The structure of [Link] is: [St_Id, St_Name, Game_Name, Result]
Where
 St_Id is Student Id (integer)
 St_Name is Student Name(string)
 Game_Name is name of game in which student is participating (string)
 Result is result of the game whose value can be either ‘Won’, ‘Lost’ or ‘Tie’

For efficiently maintaining data of the event, Vedansh wants to write the following user
defined functions:
Accept( ) – to accept a record from the user and add it to the file.
[Link]. The column headings should also be added on top of the csv file.

wonCount( ) – to count the number of students who have won any event.
As a Python expert, help him complete the task.
21. MY SQL EMPLOYEE & SALARY

22. MY SQL FLIGHTS & FARES

Page 6 of 7
23. MY SQL GARMET & FABRIC

24. MY SQL DEPT & WORKER

25. MY SQL EMPLOYEES AND EMPSALARY

Page 7 of 7

You might also like