Python Programming - Practice Exercise 04
Python Programming - Practice Exercise 04
Python Programming
Practice Exercise 04
21. Write a program to find the second largest number in a given list of integers.
22. Take a list of numbers from the user and remove all even numbers from it.
23. Accept elements of two sets from the user and perform union, intersection, and
difference operations.
24. Take student details (name, roll no, marks) and store them in a dictionary, then
allow the user to search by roll number.
25. Create a dictionary of products with prices and write a function to calculate the
total cost of items selected by the user.
🧾
Project 7. Grocery Store Billing System
grocery_items = {
"Rice": 60, # price per kg
"Wheat Flour": 45,
"Sugar": 40,
"Oil": 120, # price per litre
"Milk": 50, # price per litre
"Eggs": 6 # price per egg
}
🧮 Billing Logic:
● For each item selected, multiply the quantity by the unit price.
● Keep track of each item’s subtotal.
● Sum up all subtotals to get the total bill.
● If the total exceeds Rs. 1000, apply 10% discount.
📤 Expected Output:
✅ Program Start:
Welcome to Python Grocery Store 🛒
Here is the list of available items:
-----------------------------------------
Item Name | Price (Rs. per unit)
-----------------------------------------
Rice | 60
Wheat Flour | 45
Sugar | 40
Oil | 120
Milk | 50
Eggs | 6
-----------------------------------------
How many different items would you like to buy? 3
✅ User Input 1:
✅ User Input 2:
Enter item name: Milk
Enter quantity (in Litres): 3
✅ User Input 3:
Enter item name: Eggs
Enter quantity (in Units): 10
✅ Final Output:
************ Final Bill ************
Item Qty Price Subtotal
-----------------------------------------
Rice 2 60 120
Milk 3 50 150
Eggs 10 6 60
-----------------------------------------
🔁 Program Flow Summary:
1. Display available items and prices.
2. Ask the user to select items and enter quantities.
3. Store each selection as a tuple and add to a list.
4. After input is complete, calculate total.
5. Apply discount if total > Rs. 1000.
6. Print final bill in tabular format.
26. Create a class BankAccount with methods to deposit, withdraw, and check
balance. Initialize with account number and balance.
27. Write a program that uses a lambda function to multiply three numbers entered by
the user.
28. Write a program to find and print the longest word in a text file.
29. Write a program that uses the __init__ method to initialize object data, and
__del__ to clean up.
30. Write a class Library that stores a collection of books. Add methods to
add_book, remove_book, and display_books.
📝 Scenario: You have been hired to design a simple Railway Reservation System for a
small train booking counter. This system should help users to book tickets, cancel them, and
view all existing bookings using a console-based interface.
The system will be developed using Object-Oriented Programming (OOP) concepts in Python
such as classes, objects, encapsulation, constructors, and basic file or list storage.
🎯 Objectives:
● Implement real-world ticket booking functionality using Python.
● Apply OOP concepts such as:
○ Classes & Objects
○ Encapsulation
○ Constructors
○ List or Dictionary for Data Handling
● Provide a menu-driven interface for user interaction.
■ ticket_id (auto-generated)
■ passenger_name
■ age
■ source
■ destination
■ status (e.g., Confirmed, Cancelled)
○ Constructor: To initialize all fields (except ticket_id, which should be
auto-generated).