A complete beginner-friendly course on Python, CRUD operations, and command-line application development.
In this tutorial, you will learn how to build a complete **command-line Car Rental System** using Python. This project teaches:
Our system will allow the user to manage cars with features like adding cars, renting cars, viewing cars, editing details, and more.
This entire project will use a simple Python list of dictionaries:
cars = [] # list to store all car records
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.")
# ================================
# 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()