Build a Python CMD Car Rental System 🚗🐍

A complete beginner-friendly course on Python, CRUD operations, and command-line application development.

📘 Table of Contents
  • Introduction
  • Project Overview
  • Step 1: Setting Up Data Structure
  • Step 2: Add a Car (Create)
  • Step 3: View Cars (Read)
  • Step 4: Update Car Details
  • Step 5: Delete a Car
  • Step 6: CLI Menu Loop
  • Step 7: Final Complete Program

Introduction

In this tutorial, you will learn how to build a complete **command-line Car Rental System** using Python. This project teaches:

Project Overview

Our system will allow the user to manage cars with features like adding cars, renting cars, viewing cars, editing details, and more.

Note: This is a CMD project. No GUI required. Works on Windows, Mac, Linux.

Step 1 — Data Structure

This entire project will use a simple Python list of dictionaries:

cars = []  # list to store all car records

Step 2 — Add Car (CREATE)

def add_car():
    print("\n-- Add New Car --")
    brand = input("Car Brand: ")
    model = input("Car Model: ")
    price = float(input("Rental Price Per Day: "))

    car = {
        "brand": brand,
        "model": model,
        "price": price,
        "rented": False
    }

    cars.append(car)
    print("Car added successfully!")

Step 3 — View Cars (READ)

def view_cars():
    print("\n-- Available Cars --")
    if not cars:
        print("No cars available.")
        return

    for index, car in enumerate(cars):
        status = "Rented" if car["rented"] else "Available"
        print(f"{index}. {car['brand']} {car['model']} - ${car['price']} - {status}")

Step 4 — Update Car

def update_car():
    view_cars()
    id = int(input("Select Car ID to Update: "))

    if id >= len(cars):
        print("Invalid ID.")
        return

    car = cars[id]

    print("Leave blank to keep old value.")
    new_brand = input("New Brand: ")
    new_model = input("New Model: ")
    new_price = input("New Price: ")

    if new_brand:
        car["brand"] = new_brand
    if new_model:
        car["model"] = new_model
    if new_price:
        car["price"] = float(new_price)

    print("Car updated successfully!")

Step 5 — Delete Car

def delete_car():
    view_cars()
    id = int(input("Select Car ID to Delete: "))

    if id >= len(cars):
        print("Invalid ID.")
        return

    cars.pop(id)
    print("Car deleted successfully!")

Step 6 — Main Menu Loop

def menu():
    while True:
        print("\n==== Car Rental System ====")
        print("1. Add Car")
        print("2. View Cars")
        print("3. Update Car")
        print("4. Delete Car")
        print("5. Exit")

        choice = input("Enter choice: ")

        if choice == "1":
            add_car()
        elif choice == "2":
            view_cars()
        elif choice == "3":
            update_car()
        elif choice == "4":
            delete_car()
        elif choice == "5":
            print("Goodbye!")
            break
        else:
            print("Invalid option, try again.")

Final Complete Program 🎉

# ================================
# Simple Python Car Rental System
# EgoTECH World
# ================================

cars = []


def add_car():
    print("\n-- Add New Car --")
    brand = input("Car Brand: ")
    model = input("Car Model: ")
    price = float(input("Rental Price Per Day: "))

    car = {"brand": brand, "model": model, "price": price, "rented": False}
    cars.append(car)
    print("Car added successfully!")


def view_cars():
    print("\n-- Available Cars --")
    if not cars:
        print("No cars available.")
        return
    for index, car in enumerate(cars):
        status = "Rented" if car["rented"] else "Available"
        print(f"{index}. {car['brand']} {car['model']} - ${car['price']} - {status}")


def update_car():
    view_cars()
    id = int(input("Select Car ID to Update: "))
    if id >= len(cars):
        print("Invalid ID.")
        return
    car = cars[id]
    print("Leave blank to keep old value.")
    new_brand = input("New Brand: ")
    new_model = input("New Model: ")
    new_price = input("New Price: ")
    if new_brand:
        car["brand"] = new_brand
    if new_model:
        car["model"] = new_model
    if new_price:
        car["price"] = float(new_price)
    print("Car updated successfully!")


def delete_car():
    view_cars()
    id = int(input("Select Car ID to Delete: "))
    if id >= len(cars):
        print("Invalid ID.")
        return
    cars.pop(id)
    print("Car deleted successfully!")


def menu():
    while True:
        print("\n==== Car Rental System ====")
        print("1. Add Car")
        print("2. View Cars")
        print("3. Update Car")
        print("4. Delete Car")
        print("5. Exit")
        choice = input("Enter choice: ")
        if choice == "1":
            add_car()
        elif choice == "2":
            view_cars()
        elif choice == "3":
            update_car()
        elif choice == "4":
            delete_car()
        elif choice == "5":
            print("Goodbye!")
            break
        else:
            print("Invalid option, try again.")


menu()