Sure! Below is a simple example of a restaurant booking system written in Python. This example uses a command-line interface and stores bookings in memory (no database). It allows users to:
View available tables
Make a booking
View all bookings
Cancel a booking
You can expand or modify this as needed.
python
import datetime
class RestaurantBookingSystem:
def __init__(self):
# Let's assume the restaurant has 5 tables
self.tables = [1, 2, 3, 4, 5]
# Bookings stored as a list of dicts
self.bookings = []
def show_tables(self):
print("Available tables: ", self.tables)
def show_bookings(self):
if not self.bookings:
print("No bookings yet.")
return
print("Current bookings:")
for booking in self.bookings:
print(f"Table {booking['table']} on {booking['date']} at {booking['time']} for {booking['name']}")
def check_availability(self, table, date, time):
for booking in self.bookings:
if booking['table'] == table and booking['date'] == date and booking['time'] == time:
return False
return True
def make_booking(self):
name = input("Enter your name: ").strip()
date = input("Enter booking date (YYYY-MM-DD): ").strip()
time = input("Enter booking time (HH:MM, 24-hour format): ").strip()
# Validate date and time format
try:
datetime.datetime.strptime(date, "%Y-%m-%d")
datetime.datetime.strptime(time, "%H:%M")
except ValueError:
print("Invalid date or time format.")
return
self.show_tables()
try:
table = int(input("Choose a table number from the available tables: "))
except ValueError:
print("Invalid table number.")
return
if table not in self.tables:
print("Table does not exist.")
return
if not self.check_availability(table, date, time):
print("Sorry, this table is already booked at that date and time.")
return
self.bookings.append({
'name': name,
'date': date,
'time': time,
'table': table
})
print(f"Booking confirmed for {name} at table {table} on {date} at {time}.")
def cancel_booking(self):
name = input("Enter your name to cancel booking: ").strip()
date = input("Enter booking date (YYYY-MM-DD): ").strip()
time = input("Enter booking time (HH:MM): ").strip()
for booking in self.bookings:
if booking['name'] == name and booking['date'] == date and booking['time'] == time:
self.bookings.remove(booking)
print("Booking cancelled.")
return
print("No matching booking found.")
def run(self):
while True:
print("\n--- Restaurant Booking System ---")
print("1. Show available tables")
print("2. Make a booking")
print("3. Show all bookings")
print("4. Cancel a booking")
print("5. Exit")
choice = input("Choose an option: ").strip()
if choice == '1':
self.show_tables()
elif choice == '2':
self.make_booking()
elif choice == '3':
self.show_bookings()
elif choice == '4':
self.cancel_booking()
elif choice == '5':
print("Goodbye!")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
system = RestaurantBookingSystem()
system.run()
How to use:
Run the script.
Choose options from the menu.
Enter booking details when prompted.
If you want a more advanced system (e.g., with a database, web interface, or GUI), let me know!