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

sction a

The document outlines a series of Python programming tasks, each requiring the creation of user-defined functions for various operations such as modifying lists, file handling, and implementing stack operations. Examples include incrementing/decrementing numbers in a list, creating and reading from text files, and managing stacks of data. Each task is accompanied by a specified program date, indicating when the task was to be completed.

Uploaded by

shaheem.syed
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)
5 views

sction a

The document outlines a series of Python programming tasks, each requiring the creation of user-defined functions for various operations such as modifying lists, file handling, and implementing stack operations. Examples include incrementing/decrementing numbers in a list, creating and reading from text files, and managing stacks of data. Each task is accompanied by a specified program date, indicating when the task was to be completed.

Uploaded by

shaheem.syed
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/ 42

Section A – Python Program

1. Write a user defined function EOReplace() in Python, which accepts a list L of


numbers.

Thereafter, it increments all even numbers by 1 and decrements all odd numbers by 1.

Example:

If Sample Input data of the list is:

L=[10,21,30,40,35,55]

Output will be:

L=[11,20,31,41,34,54]

Program : 29/04/2024

Output:
2. Write a user defined function in Python named Puzzle(W,N) which takes the
argument W as an 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 word “TELEVISION” and N is 3, then the function should
return the string “TE_EV_SI_N”.

Program : 10/05/2024

Output:
3. Write a menu driven Python Program to do the following

a. A user defined function CreateFile() to create a text file PYTHON.TXT with

multiple lines of text

b. A user defined function DisplayPython() to read and display the lines from a text file
PYTHON.TXT which starts with the word ‘The’.

Program: 10/05/2024
4. Write a menu driven Python Program to do the following

a. A user defined function CreateFile() to create a text file Details.txt with multiple lines
of text

b. Write a Python function DigWords() that count and display the words ending with digit
in a text file Details.txt

program: 17/05/2024
Output:
5. Write a menu driven Python Program to do the following

a. A user defined function CreateFile() to create a text file SAMPLE.TXT with multiple
lines of text

b. Write a function Change() to read the text file SAMPLE.TXT line by line and display
each word separated by#

program: 17/05/2024
Output:
6. Write a menu driven Python Program to do the following

a. A user defined function CreateFile() to create a text file STORY.TXT with multiple lines
of text

b. Write a function showlines() which reads the contents of the file STORY.TXT and
display every sentence in separate line

program: 24/05/2024
Output:
7. Write a menu driven Python Program to do the following

a. A user defined function CreateFile() to create a text file SAMPLE.TXT with multiple
lines of text

b. write a function count() to read the text file SAMPLE.TXT and display the number of
vowels/ consonants/ uppercase/ lowercase and other characters in the file.

Program: 24/05/2024
Output:
8. Write a menu driven Python Program to do the following

a. A user defined function CreateFile() to create a text file CBSE.TXT with multiple lines
of text

b. Write the definition of a function Long_Line() in Python, which should reads the
contents of the text file "CBSE.TXT" and display the lines with more than 5 words in it.

Program: 31/05/2024
Output:
9. Write a menu driven Python Program to do the following

a. A user defined function CreateFile() to create a text file SAMPLE1.TXT with multiple
line of text

b. Write a user defined function RMlines_A() to remove all the lines that contain the
character 'a' in SAMPLE1.TXT and write it to another file SAMPLE2.TXT.

program: 31/05/2024
Output:
10.Write a menu driven Python Program to do the following

a. A user defined function CreateFile() to create a binary file “Student.dat” having


structure [RollNo,Name]

b. Write a function/method Search () to read the contents of “student.dat” and search

program: 3/06/2024
Output:
11.Consider a file, SPORT.DAT, containing records of the following structure:

[SportName, TeamName, No_Players]. Write a menu driven Python Program to do the

following

a. A user defined function CreateFile() to store details of n records to file SPORT.DAT

b. Write a function, copyData(), that reads contents from the file SPORT.DAT and copies
the records with Sport name as “Basket Ball” to the file named BASKET.DAT. The
function should return the total number of records copied to the file BASKET.DAT.

Program: 07/06/2024
Output:
12. A Binary file, CINEMA.DAT has the following structure: {MNO:[MNAME, MTYPE]}
Where MNO – Movie Number, MNAME – Movie Name, MTYPE is Movie Type Write a
menu driven Python Program to do the following

a. A user defined function CreateBinary() to store details of n records to file


CINEMA.DAT

b. Write a user defined function, findType(mtype), that accepts mtype as parameter and
displays all the records from the binary file CINEMA.DAT, that have the value of Movie
Type as mtype.

Program: 11/06/2024
Output:
13.Consider the binary file, “Items.dat” containing records stored in the
format:{item_id:[item_name,amount]} Write a menu driven Python Program to do the
following

a. A user defined function CreateFile(n) to store n records to the file ITEMS.DAT

b. Write a function Copy_New() that copies all records whose amount is greater than
1000 to NEW_ITEMS.DAT

program: 14/06/2024
output:
14. A csv file “Book.csv” has structure [B_ID, B_Name, Author, Price]. Write a menu
driven Python Program to do the following

a. A user defined function Add_Book() :Takes the details of the books and add them to
“Book.csv”. Each record consists of a list with field elements such as B_ID, B_Name,
Author and Price respectively. The column headings should also be added on top of the
csv file.

b. Write a function CountRec(Author) in Python which accepts the Author name as


parameter and count and return number of books belongs to that author from the binary
file “Book.csv”

Program: 20/06/2024
Output:
15. Write a menu driven Python Program to do the following. A user defined function

a. Add_Device() to add details to file “Peripheral.csv” has structure [P_id,P_name,Price]


The column headings should also be added on top of the csv file.

b. Write a function Count_Device() to count and display number of peripheral devices


whose price is less than 1000.

Program: 27/06/2024
Output:
16. Write a menu driven program to implement STACK operations on a stack with train
names.

a. Add(Trains,name)—add an element in Stack

b. Delete(Trains)—delete an element from the stack, check whether the stack is empty
or not before deletion

c. Display(Trains)—to display the stack

d. Search(Trains,Name) to search for a particular name stored in the stack

program: 03/09/2024
17. Write a menu-driven program to implement STACK operations on a list, NList
contains following record as list elements: [City, Country, distance from Delhi]. Each of
these records are nested together to form a nested list. Write the following user defined
functions in Python to perform the specified operations on the stack named travel.

a. Push_element(NList): It takes the nested list as an argument and pushes a list object
containing name of the city and country, which are not in India and distance is less than
3500 km from Delhi.

b. Pop_element(): It pops the objects from the stack and displays them. Also, the
function should display “Stack Empty” when there are no elements in the stack

program: 10/09/2024
Output:
18. Write a menu-driven program to implement STACK operations

a. Write a function in Python, Push(SItem) where , SItem is a dictionary containing the


details of stationary items– {Sname:price}. The function should push the names of
those items in the stack who have price greater than 75. Also display the count of
elements pushed into the stack.

b. Pop() to pop and display the content of the stack.

Program: 12/09/2024
Output:
19. Alam has a list containing 10 integers. You need to help him create a menu driven
program with separate user defined functions to perform the following operations based
on this list.

a. PushEven(L): Traverse the content of the list, L and push the even numbers into a
stack.

b. Pop() :pop and display the content of the stack. The function should also return None
when there are no more numbers left in the stack.

Program: 16/09/2024
Output:
20. Consider a list named Nums which contains random integers. Write the following
user defined functions in Python and perform the specified operations on a stack
named BigNums.

a. PushBig() : It checks every number from the list Nums and pushes all such numbers
which have 5 or more digits into the stack, BigNums.

b. PopBig() : It pops the numbers from the stack, BigNums and displays them. The
function should also display "Stack Empty" when there are no more numbers left in the
stack.

Program: 20/09/2024
Output:

You might also like