Post

Python Primer – Parking System Programming Assignments

Practice for Python Primer such as Parking System Programming Assignments

Python Primer – Parking System Programming Assignments

Parking System Programming Assignments

The Parking Assignment System is a menu-driven Python program designed to help students practice core programming concepts through a realistic parking management scenario.

The system consists of five independent but related modules (Q1–Q5). Each module focuses on a specific level of difficulty and programming skills, ranging from basic data processing to full system simulation.

Students can select any module from the menu and execute it independently.

Main Menu:

1
2
3
4
5
6
7
8
===== PARKING ASSIGNMENT MENU =====
1. Q1 – Parking Fee Calculator
2. Q2 – Parking Slot Management
3. Q3 – Parking Violation Detection
4. Q4 – Smart Parking Statistics
5. Q5 – Full Parking System (Capstone)
6. Exit
==================================

Code templates:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# =========================================
# PARKING SYSTEM – ALL 5 QUESTIONS IN ONE
# =========================================

# ---------- VARIABLES ----------


# =========================================
# Q1 – Parking Fee Calculator
# =========================================
def question_1():
  print()

# =========================================
# Q2 – Parking Slot Management
# =========================================
def question_2():
  print()

# =========================================
# Q3 – Parking Violation Detection
# =========================================
def question_3():
  print()

# =========================================
# Q4 – Smart Parking Statistics
# =========================================
def question_4():
  print()

# =========================================
# Q5 – Full Parking System (Menu-based)
# =========================================
def question_5():
    print()

# =========================================
# MAIN MENU
# =========================================
def main():
    while True:
        print("\n===== PARKING ASSIGNMENT MENU =====")
        print("1. Q1 – Parking Fee Calculator")
        print("2. Q2 – Parking Slot Management")
        print("3. Q3 – Parking Violation Detection")
        print("4. Q4 – Smart Parking Statistics")
        print("5. Q5 – Full Parking System")
        print("0. Exit")
        print("==================================")

        choice = input("Choose an option: ")

        if choice == "1":
            question_1()
        elif choice == "2":
            question_2()
        elif choice == "3":
            question_3()
        elif choice == "4":
            question_4()
        elif choice == "5":
            question_5()
        elif choice == "0":
            print("Goodbye!")
            break
        else:
            print("Invalid choice. Try again.")


# ---------- RUN PROGRAM ----------
main()

1. Parking Fee Calculator

Problem Description

You are asked to build a program that calculates parking fees for multiple vehicles parked in a parking lot during a single day. Each vehicle has a type and a parking duration (in hours). The system must calculate the correct fee based on predefined pricing rules.

This module calculates parking fees for a list of vehicles parked during a single day.

  • Uses basic data structures such as tuples and dictionaries
  • Applies arithmetic expressions and conditional logic
  • Ignores invalid parking durations
  • Produces total revenue and vehicle count by type

Input: A list of tuples, where each tuple represents one vehicle:

1
(vehicle_id: str, vehicle_type: str, hours_parked: float)

Example:

1
2
3
4
5
6
vehicles = [
    ("A01", "bike", 2.5),
    ("B02", "car", 12),
    ("C03", "truck", 15),
    ("D04", "car", -1)
]

Pricing Rules

Vehicle TypePrice per HourMaximum Fee
bike5,00030,000
car10,000100,000
truck20,000200,000

Output

  • A dictionary showing the parking fee for each valid vehicle
  • The total revenue
  • The number of vehicles by type

Rules

  • Vehicles with hours_parked <= 0 must be ignored using continue
  • The fee cannot exceed the maximum fee
  • Use a dict to store pricing information

Example Output

1
2
3
4
5
6
7
8
{
    "A01": 12500,
    "B02": 100000,
    "C03": 200000
}

Total revenue: 312500
Vehicle count: {"bike": 1, "car": 1, "truck": 1}

2. Parking Slot Management System

Problem Description

Simulate a parking lot entry–exit management system. The parking lot has a limited number of slots. Vehicles can enter or leave based on events.

This module simulates vehicle entry and exit in a parking lot with limited capacity.

  • Manages available slots using a set
  • Processes a sequence of IN/OUT events
  • Prevents overcapacity and invalid exits
  • Terminates processing when a STOP event is encountered

Input

  • An integer capacity – total parking slots
  • A list of parking events represented as tuples:
1
(event_type: str, vehicle_id: str)

Example:

1
2
3
4
5
6
7
8
9
capacity = 2
events = [
    ("IN", "A01"),
    ("IN", "B02"),
    ("IN", "C03"),
    ("OUT", "A01"),
    ("IN", "C03"),
    ("STOP", "")
]

Output After each event, print:

  • Vehicles currently parked
  • Number of available slots

Rules

  • Use a set to store vehicles currently parked
  • If the parking lot is full, reject new vehicles
  • If a vehicle tries to leave but is not present, ignore it
  • Stop processing events when “STOP” is encountered

Example Output:

1
2
3
4
5
IN A01  Parked: {'A01'}, Available slots: 1
IN B02  Parked: {'A01', 'B02'}, Available slots: 0
IN C03  Parking full
OUT A01  Parked: {'B02'}, Available slots: 1
IN C03  Parked: {'B02', 'C03'}, Available slots: 0

3. Parking Violation Detection System

Problem Description

Your task is to detect parking violations based on incorrect payment or illegal parking duration.

This module detects parking violations based on incorrect payment or illegal parking behavior.

  • Validates vehicle types and parking duration
  • Detects underpayment and overstaying
  • Records violations in a dictionary
  • Calculates total unpaid revenue

Input: A dictionary where:

1
vehicle_id: (vehicle_type, hours_parked, amount_paid)

Example:

1
2
3
4
5
6
records = {
    "A01": ("car", 5, 30000),
    "B02": ("bike", 30, 10000),
    "C03": ("truck", 10, 150000),
    "D04": ("bus", 3, 50000)
}

Output

  • A dictionary of violating vehicles and reasons
  • Total unpaid amount

Violation Conditions: A vehicle is considered in violation if:

  • Paid amount < required parking fee
  • Parking duration > 24 hours
  • Vehicle type is invalid

Example Output

1
2
3
4
5
6
{
    "B02": "Exceeded maximum parking duration",
    "D04": "Invalid vehicle type"
}

Total unpaid amount: 20000

4. Smart Parking Statistics Analyzer (Hard)

Problem Description

Analyze parking data to produce usage statistics.

This module analyzes historical parking records to generate useful statistics.

  • Computes average parking duration by vehicle type
  • Identifies the longest parked vehicle
  • Counts unique vehicles using a set
  • Ignores invalid or inconsistent records

Input: A list of records:

1
(vehicle_id, vehicle_type, hour_in, hour_out)

Example:

1
2
3
4
5
6
data = [
    ("A01", "car", 8, 12),
    ("B02", "bike", 9, 10),
    ("C03", "car", 7, 18),
    ("D04", "truck", 14, 13)
]

Output:

  • Average parking duration per vehicle type
  • Vehicle with the longest parking duration
  • Number of unique vehicles

Rules

  • Ignore invalid records where hour_out < hour_in
  • Use a set to count unique vehicles
  • Do not use external libraries

Example Output

1
2
3
4
5
6
Average duration:
car: 7.5 hours
bike: 1.0 hours

Longest parking vehicle: C03 (11 hours)
Unique vehicles: 3

5. Full Parking System Simulation

Problem Description

Build a complete interactive parking system simulation.

This is the most advanced module, integrating all previous concepts into a complete parking system.

  • Provides an interactive menu-based interface
  • Supports real-time vehicle check-in and check-out
  • Tracks parking status, revenue, and history
  • Applies peak-hour pricing rules
  • Produces a final summary report on exit

Rules:

ItemValue
Maximum parking slots50
Supported vehicle typesbike, car, truck
Parking fee rulefee = hours × price_per_hour
Peak hours surcharge+20% (7–9, 17–19)
Data structures requiredset, dict, tuple

Input/Output follow structure:

OptionDescription
1Vehicle check-in
2Vehicle check-out
3Show parking status
4Show revenue report
0Exit system

Option 1 – Vehicle Check-in

Input

Input FieldTypeDescription
vehicle_idstringUnique identifier of the vehicle
vehicle_typestringOne of: bike, car, truck
hour_infloatEntry time (0–24)

Rules

ConditionAction
Parking is fullReject check-in
vehicle_type invalidReject check-in
vehicle already parkedReject check-in
hour_in not in 0–24Reject check-in

Output

ResultMessage
SuccessVehicle <id> parked successfully.
FailureError message explaining the reason

Option 2 – Vehicle Check-out

Input

Input FieldTypeDescription
vehicle_idstringVehicle to be checked out
hour_outfloatExit time (0–24)

Rules:

ConditionAction
vehicle not foundReject check-out
hour_out ≤ hour_inReject check-out

Fee Calculation

StepFormula
Parking durationhour_out − hour_in
Base feeduration × price_per_hour
Peak hour surchargefee × 1.2 if hour_in in peak

Output

ResultMessage
SuccessParking fee: <amount> VND
FailureError message explaining the reason

Option 3 – Show Parking Status

Output

FieldDescription
Total parked vehiclesCurrent number of vehicles
Vehicle listvehicle_id, type, hour_in
Available slotsRemaining capacity

Example

1
2
3
4
Vehicles currently parked: 2
A01 (car), entered at 8.0
B02 (bike), entered at 9.5
Available slots: 48

Option 4 – Show Revenue Report

Output

FieldDescription
Total revenueSum of all collected fees
Vehicles by typeCount per vehicle type
Longest parked vehiclevehicle_id and duration

Example Output

1
2
3
4
5
Total revenue: 360000
car: 3
bike: 2
truck: 1
Longest parked vehicle: C03 (12.0 hours)

Option 0 – Exit System

Output

ActionResult
Exit programPrint final revenue report
Program endsNo further input accepted
This post is licensed under CC BY 4.0 by the author.