Python Programming Examples: Financial, Retail, and Travel Systems

1. Automated Teller Machine (ATM) System

Problem Summary: Create a menu allowing users to Deposit, Withdraw, Change PIN, and Check Balance. Key Logic: Use a while True loop to keep the program running until the “Exit” option is chosen.

Initial Setup

# --- INITIAL SETUP ---
balance = 5000  # Starting money
pin = 1234      # Default PIN
print("--- WELCOME TO ATM ---")

ATM Operations Loop

while True:
    # 1. Display Menu [cite: 16]
    print("\n1. Deposit  2. Withdraw  3. Check Balance  4. Change PIN  5. Exit")
    choice = input("Enter choice: ")

    # --- DEPOSIT [cite: 7] ---
    if choice == '1':
        amount = float(input("Enter amount to deposit: "))
        if amount > 0:
            balance = balance + amount
            print(f"Success! New Balance: {balance}")
        else:
            print("Invalid amount.")

    # --- WITHDRAW [cite: 8] ---
    elif choice == '2':
        amount = float(input("Enter amount to withdraw: "))
        if amount > balance:
            print("Insufficient Balance!")
        elif amount <= 0:
            print("Invalid amount.")
        else:
            # Check PIN before withdrawing (Security) [cite: 14]
            user_pin = int(input("Enter PIN to confirm: "))
            if user_pin == pin:
                balance = balance - amount
                print(f"Withdrawal successful. Remaining: {balance}")
            else:
                print("Wrong PIN!")

    # --- CHECK BALANCE [cite: 10] ---
    elif choice == '3':
        print(f"Current Balance: {balance}")

    # --- CHANGE PIN [cite: 9] ---
    elif choice == '4':
        old_pin = int(input("Enter current PIN: "))
        if old_pin == pin:
            new_pin = int(input("Enter new 4-digit PIN: "))
            pin = new_pin
            print("PIN Changed Successfully!")
        else:
            print("Wrong current PIN.")

    # --- EXIT [cite: 11] ---
    elif choice == '5':
        print("Thank you. Goodbye!")
        break
    
    else:
        print("Invalid choice, try again.")

2. Grocery Store Inventory and Sales System

Problem Summary: Manage five items (30kg initial quantity each). Apply dynamic discounts to fruits based on their “freshness” (simulated by the current day).

Data Setup

The inventory is stored in a dictionary. The format for each item is: [Quantity (kg), Cost Price, Base Selling Price, Is_Fruit (Boolean)].

# --- DATA SETUP [cite: 35] ---
items = {
    "Apple":  [30, 100, 150, True],  # True means it is a fruit
    "Banana": [30, 40, 60, True],
    "Rice":   [30, 50, 70, False],  # False means dry item (no rot)
    "Sugar":  [30, 40, 55, False],
    "Orange": [30, 80, 120, True]
}
total_profit = 0
# Simulate shopping
day = int(input("Enter current Day (1-7): "))

Sales and Discount Logic

while True:
    print("\n--- STOCK AVAILABLE ---")
    for name, data in items.items():
        print(f"{name}: {data[0]}kg left") # Display Stock
    
    choice = input("Enter item name to buy (or 'exit'): ").capitalize()
    
    if choice == 'Exit':
        break
    
    # Validation [cite: 36]
    if choice in items:
        qty = float(input(f"How many kg of {choice}?: "))
        
        # Check if enough stock exists [cite: 32]
        if qty <= items[choice][0]:
            cost_price = items[choice][1]
            base_sell = items[choice][2]
            is_fruit = items[choice][3]
            
            # --- FRESHNESS LOGIC [cite: 26-31] ---
            selling_price = base_sell
            if is_fruit:
                if day == 4:
                    selling_price = base_sell * 0.90 # 10% off
                elif day == 5:
                    selling_price = base_sell * 0.85 # 15% off
                elif day == 6:
                    selling_price = base_sell * 0.80 # 20% off
                elif day == 7:
                    selling_price = base_sell * 0.75 # 25% off
            
            # Update Stock
            items[choice][0] -= qty
            
            # Calculate Profit for this sale [cite: 33]
            # Profit = (Selling Price - Cost Price) * Quantity
            profit = (selling_price - cost_price) * qty
            total_profit += profit
            
            print(f"Sold {qty}kg of {choice} for {selling_price * qty:.2f}")
        else:
            print("Not enough stock!")
    else:
        print("Item not found!")

# --- FINAL REPORT [cite: 37] ---
print("\n--- 7 DAY REPORT ---")
print(f"Total Profit/Loss: {total_profit:.2f}")
print("Remaining Stock:", items)

3. Theater Hall Seat Booking Simulation

Problem Summary: Visualize seats (5×5 grid), and handle booking requests for single seats or multiple adjacent seats within the same row.

Setup and Initialization

import random
# --- SETUP SEATS [cite: 55] ---
# 5 rows, 5 seats per row. 0 is Empty, 1 is Booked.
seats = [[0, 0, 0, 0, 0] for _ in range(5)]

# Randomly book some seats at start [cite: 57]
for _ in range(5):
    r = random.randint(0, 4)
    c = random.randint(0, 4)
    seats[r][c] = 1 # Mark as booked

def show_hall():
    print("\n--- SCREEN THIS WAY ---")
    for r in range(5):
        print(f"Row {r}: {seats[r]}") # [cite: 45]

Booking Interface

while True:
    show_hall()
    print("\n1. Book Single Seat  2. Book Multiple  3. Exit")
    opt = input("Choice: ")

    # --- BOOK SINGLE SEAT [cite: 47] ---
    if opt == '1':
        r = int(input("Enter Row (0-4): "))
        c = int(input("Enter Seat (0-4): "))
        
        # Validation [cite: 52]
        if 0 <= r < 5 and 0 <= c < 5:
            if seats[r][c] == 0:
                seats[r][c] = 1
                print("Booked!")
            else:
                print("Already Booked!")
        else:
            print("Invalid Seat Number.")

    # --- BOOK MULTIPLE SEATS [cite: 48] ---
    elif opt == '2':
        num = int(input("How many seats? "))
        mode = input("Same row only? (y/n): ") # [cite: 50]
        booked = False
        
        if mode == 'y':
            # Try to find 'num' empty seats in one row
            for r in range(5):
                # Count empty spots in this row
                if seats[r].count(0) >= num:
                    # Simple booking logic: fill first available spots
                    count = 0
                    for c in range(5):
                        if count < num and seats[r][c] == 0:
                            seats[r][c] = 1
                            count += 1
                    print(f"Booked {num} seats in Row {r}")
                    booked = True
                    break
            
            if not booked:
                print("Cannot find adjacent seats.")
    
    elif opt == '3':
        break

4. Travel Agent Budget Planner

Problem Summary: Given a list of 10 destinations with associated costs, take the user’s total budget and number of travelers, and suggest affordable places.

Destination Dataset

# --- DATASET [cite: 65] ---
destinations = [
    {"Country": "Thailand", "Flight": 15000, "Stay": 10000},
    {"Country": "Singapore", "Flight": 25000, "Stay": 20000},
    {"Country": "Vietnam",  "Flight": 18000, "Stay": 12000},
    {"Country": "Dubai",    "Flight": 22000, "Stay": 25000},
    {"Country": "Japan",    "Flight": 45000, "Stay": 40000},
    {"Country": "Bali",     "Flight": 20000, "Stay": 15000},
    {"Country": "Nepal",    "Flight": 8000,  "Stay": 5000},
    {"Country": "SriLanka", "Flight": 12000, "Stay": 8000},
    {"Country": "Maldives", "Flight": 30000, "Stay": 35000},
    {"Country": "Europe",   "Flight": 60000, "Stay": 50000},
]

User Input and Feasibility Check

# --- USER INPUT [cite: 71] ---
print("--- TRIP PLANNER ---")
user_budget = float(input("Enter Total Budget: "))
tickets = int(input("Number of people: "))
print("\n--- SEARCH RESULTS ---")
found_option = False

# --- FEASIBILITY CHECK [cite: 75] ---
for place in destinations:
    # Calculate Total Cost
    # Note: Flight is per person, Stay is usually per trip (simplified here)
    flight_cost = place["Flight"] * tickets
    stay_cost = place["Stay"]
    total_trip_cost = flight_cost + stay_cost
    
    # Check if within budget
    if total_trip_cost <= user_budget:
        found_option = True
        print(f"\nDestination: {place['Country']}")
        print(f"Flight ({tickets} tix): {flight_cost}")
        print(f"Stay/Food: {stay_cost}") # [cite: 80]
        print(f"Total: {total_trip_cost}")
        print(f"Savings: {user_budget - total_trip_cost}")

# --- SUGGESTIONS [cite: 78] ---
if not found_option:
    print("No destinations found within this budget.")
    print("Try increasing budget or reducing ticket count.")