0% found this document useful (0 votes)
95 views8 pages

Python Programming - Practice Exercise 04

The document outlines practice exercises and projects for Python programming, including tasks like finding the second largest number in a list, creating a grocery store billing system, and developing a railway reservation system. It emphasizes the use of data structures such as dictionaries, lists, and classes to implement various functionalities. The projects aim to enhance programming skills through real-world applications and user interactions.

Uploaded by

Animesh Garv
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)
95 views8 pages

Python Programming - Practice Exercise 04

The document outlines practice exercises and projects for Python programming, including tasks like finding the second largest number in a list, creating a grocery store billing system, and developing a railway reservation system. It emphasizes the use of data structures such as dictionaries, lists, and classes to implement various functionalities. The projects aim to enhance programming skills through real-world applications and user interactions.

Uploaded by

Animesh Garv
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

​ ​ 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

🎯 Project Title: Python Grocery Billing Console Application

📘 Scenario: You have been hired as a Python developer to create a console-based


billing system for a local grocery store. This system should allow the customer to
select multiple items, enter their quantities, and then calculate and display the total bill.
The store also offers a 10% discount if the bill exceeds Rs. 1000.

🎯 Objective: Create a Python program that:

1.​ Displays a list of grocery items with their prices.


2.​ Takes input from the user to:
○​ Select multiple items to purchase.
○​ Enter the quantity of each selected item.
3.​ Calculates the total cost.

4.​ Applies a discount if applicable.


5.​ Displays a well-formatted final bill with item-wise breakdown and total.

📦 Available Items and Prices (Use a Dictionary):


You will use a dictionary like this:

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.

📥 User Input Required:


1.​ The user should be shown a menu of available items.
2.​ The user should be able to:
○​ Select an item by name.
○​ Enter the quantity (e.g., kg, litre, or unit).
○​ Continue adding more items.
3.​ The program should ask after each item:
○​ “Do you want to add more items? (Y/N)”

📤 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:

Enter item name: Rice


Enter quantity (in Kg or Litre/Unit): 2

✅ 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
-----------------------------------------

Total Amount : Rs. 330


Discount (10%) : Rs. 0
Final Amount to Pay : Rs. 330
************ Thank You for Shopping! ************

Python Concepts to be Used:

Concept Usage Example

Dictionary To store item names with prices

List To store each item’s billing info (as a tuple)

Tuple For individual item records (e.g., ("Milk", 3, 50, 150))

Set (Optional) To avoid duplicate item names if needed

Loops & Conditions For repeated inputs, calculations, and decision-making


🔁 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.

Project 8. Railway Reservation System

📌 Project Title: Console-Based Railway Ticket Booking System Using


Python OOP

📝 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.

🏗️ System Requirements & Features:


✅ Classes to Implement:
1.​ Class: Ticket
○​ Attributes:

■​ 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).​

2.​ Class: RailwayReservationSystem


○​ Attributes:
■​ tickets → A list to store all Ticket objects
■​ next_ticket_id → A counter to assign unique ticket IDs
○​ Methods:
■​ book_ticket() → Accept passenger info and store ticket
■​ cancel_ticket(ticket_id) → Cancel a ticket based on ID
■​ view_all_bookings() → Display all booked tickets
■​ find_ticket(ticket_id) → (Optional) Return ticket by ID

📥 User Input Requirements:


●​ Passenger Name
●​ Age
●​ Source Station
●​ Destination Station
●​ Option to cancel using ticket ID

📤 Expected Console Output Example:


===== Railway Reservation System =====
1. Book Ticket
2. Cancel Ticket
3. View All Bookings
4. Exit
Enter your choice: 1

Enter passenger name: Raj Kumar


Enter age: 28
Enter source station: Delhi
Enter destination station: Mumbai

Ticket booked successfully! Ticket ID: 1001

===== Railway Reservation System =====


1. Book Ticket
2. Cancel Ticket
3. View All Bookings
4. Exit
Enter your choice: 3

--- All Bookings ---


Ticket ID: 1001
Name: Raj Kumar | Age: 28
From: Delhi | To: Mumbai
Status: Confirmed

Sample Data Flow:

●​ First booking: ticket ID = 1001


●​ Second booking: ticket ID = 1002
●​ If ticket ID 1002 is cancelled, status should be updated to "Cancelled"

Bonus Enhancements (Optional):

🚆 Train Seat Availability Check:


●​ Set a maximum number of tickets (e.g., 50).
●​ Prevent booking if all seats are filled.
●​ Keep track of available seats.

🔁 Save & Load Ticket Data (File Handling):


●​ Store all bookings in a file (tickets.txt or tickets.json) so that ticket data is
retained even after the program ends.
●​ Load this file automatically when the program starts.

🔍 Search Ticket by ID or Name:


●​ Let the user enter a ticket ID or passenger name to view specific booking details.

📄 Ticket Summary Report:


●​ Generate a summary at the end:


○​ Total tickets booked
○​ Number of active bookings
○​ Number of cancellations

📆 Add Date and Time of Journey (DOJ):


●​ Include the travel date and time in the booking details.
●​ Validate that the travel date is not in the past.

You might also like