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

cs record work python programmes

Uploaded by

srigayathriuae
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

cs record work python programmes

Uploaded by

srigayathriuae
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Section-A-Python programs

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]
(29/04/2023)
Program:

Output:
2. 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 word “TELEVISION” and N is 3, then the
function
should return the string “TE_EV_SI_N”.
(10/05/2023)
Program:

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’.
(10/05/2024)
Program:

Ouput:
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(S) where S is a parameter to the
function that count words ending with digit in a text file Details.txt
(17/05/2024)

Program:
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 #.
(17/05/2024)
Program:
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.
(24/05/2024)
Program:
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. llWrite 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.
(24/05/2024)
Program:
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.
(31/05/2024)
Program:
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
(31/05/2024)

Program:
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 for a given roll number and display the name, if not found display
appropriate message.
(03/06/2024)

Program:
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.
(07/06/2024)
Program:
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.
(11/06/2024)

Program:
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
(14/06/2024)
Program:
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”
(20/06/2024)
Program:
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.
(27/06/2024)

Program:
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.
(03/09/2024)

Program:
Output:
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.
(10/09/2024)

Program:
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.
(12/09/2024)
Program:
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.
(16/09/2024)
Program:
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.
Thefunction should also display "Stack Empty" when there are no
more numbers left in the stack.
(20/09/2024)
Program:
Output:

You might also like