0% found this document useful (0 votes)
3 views2 pages

Program Practice Set 4

The document outlines a practice set of programming exercises focused on Python functions, file handling, binary file operations, CSV file handling, and stack data structures. Each section contains specific tasks such as modifying lists, counting words in files, managing inventory, and implementing stack operations. The exercises are designed to enhance understanding of various programming concepts and techniques in Python.
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)
3 views2 pages

Program Practice Set 4

The document outlines a practice set of programming exercises focused on Python functions, file handling, binary file operations, CSV file handling, and stack data structures. Each section contains specific tasks such as modifying lists, counting words in files, managing inventory, and implementing stack operations. The exercises are designed to enhance understanding of various programming concepts and techniques in Python.
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

Day-4 Programs Practice Set (Board Focused)

1. Functions (Python Logic)


1. List Modification: Write a func Update_List(L) where if an element is
even, it's divided by 2, and if it's odd, it's tripled ($3 \times n$).
2. String Stats: Write a func Count_All(S) to count and display the number
of Lowercase Alphabets and Spaces in a string S.
3. Mutable Properties: Create a program to show how a list passed to a
function reflects changes in the main program (Pass by Reference
concept).
4. List Filtering: Write a func Filter_Price(L) that takes a list of prices and
returns a new list containing only those prices which are multiples of
100.
5. Positional vs Default: Create a func Final_Bill(Item, Qty, Tax=0.05) and
show how to call it using only 2 arguments and then using keyword
arguments for Tax.
2. Text File Handling
1. Word Search: Write a func Count_Me_My() to read "[Link]" and
count how many times the words "me" or "my" appear (case
insensitive).
2. Line Logic: Write a func Show_Long_Lines() to display all lines from
"[Link]" that have more than 10 words.
3. Digit Count: Write a func Count_Digits() to count the total number of
digits (0-9) present in a file "[Link]".
4. Specific Display: Write a func Display_Hash() to read "[Link]" and
display the entire content with each word separated by a '#' symbol.
5. File Shift: Write a func Copy_Clean() to copy all lines from "[Link]"
to "[Link]" that do not start with a special character or digit.
3. Binary File (pickle module)
1. Add Data: Write a func Add_Inventory() to input ProdID, PName, and
Stock and save them as a list in "[Link]".
2. Search Record: Write a func Search_Product(PID) to search for a
Product ID in "[Link]" and display its Stock. Show "Out of Stock" if ID
not found.
3. Quantity Update: Write a func Add_Stock(PID, Qty) to find Product ID in
"[Link]" and add the new Qty to the existing Stock.
4. Filter Records: Write a func Low_Stock() to read "[Link]" and
display names of products where Stock is less than 5.
5. File Copy: Write a func Copy_Fresh() to copy records from "[Link]"
to "[Link]" where the ExpiryDate is in '2025'.
4. CSV File Handling (csv module)
1. Create CSV: Write a func Add_Teacher() to store TID, Name, and
Subject in "[Link]".
2. Search CSV: Write a func Find_Teacher(Sub) to read "[Link]"
and print names of all teachers teaching that Subject.
3. Header Skip: Write a func Show_Data_No_Head() to read "[Link]"
and display all records excluding the first header row.
4. Counter: Write a func Count_Subject(SubName) to count how many
teachers in "[Link]" belong to the "Computer Science" department.
5. Logic Read: Write a func Show_Expensive() to read "[Link]" and
display names of items where Price * Qty is greater than 5000.
5. Stack Data Structure (LIFO)
1. Multiple Stack: Write Push_Five(Nums) and Pop_Five(S) to push numbers
divisible by 5 from a list into a stack and then pop them.
2. Dict Filter: Given a dict {'Student': Marks}, write Push_Pass(D) to push
student names into a stack if Marks >= 33.
3. Length Stack: Write Push_Long_Words(Words) to push words whose
length is greater than 4 into a stack and Pop_All() with an Underflow
check.
4. Nested List Stack: If a list is [BusNo, Route, Capacity], write a func to
push only BusNo into a stack for buses where Capacity > 50.
5. Full Stack Op: Write a menu-driven code for Push, Pop, and Peek
operations for a stack of 'Player' names in a sports team.

You might also like