0% found this document useful (0 votes)
6 views

PYTHON SOURCE CODE

The document outlines a Hotel Management System implemented in Python, which connects to a MySQL database for customer and billing management. It includes functionalities for registering customers, viewing room types, calculating room rent, viewing a restaurant menu, ordering items, calculating laundry bills, and generating final bills. The system operates through a menu-driven interface allowing users to interact with various features.

Uploaded by

Gourav Swain
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

PYTHON SOURCE CODE

The document outlines a Hotel Management System implemented in Python, which connects to a MySQL database for customer and billing management. It includes functionalities for registering customers, viewing room types, calculating room rent, viewing a restaurant menu, ordering items, calculating laundry bills, and generating final bills. The system operates through a menu-driven interface allowing users to interact with various features.

Uploaded by

Gourav Swain
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

import os

import platform

import mysql.connector

class HotelManagementSystem:

def __init__(self):

self.mydb = mysql.connector.connect(

user='root', password='akhil2005', host='localhost', database='akhil')

self.mycursor = self.mydb.cursor()

self.restaurant_bill = 0

self.laundry_bill = 0

def register_customer(self):

try:

name = input("Enter name: ")

address = input("Enter address: ")

check_in_date = input("Enter check-in date (YYYY-MM-DD): ")

check_out_date = input("Enter check-out date (YYYY-MM-DD): ")

sql = "INSERT INTO custdata(custname, addr, indate, outdate) VALUES (%s, %s, %s, %s)"

self.mycursor.execute(sql, (name, address, check_in_date, check_out_date))

self.mydb.commit()

print("Customer registered successfully!")

except Exception as e:

print(f"Error: {e}")

def view_room_types(self):

try:

print("Available room types:")

self.mycursor.execute("SELECT * FROM roomtype")


rows = self.mycursor.fetchall()

for row in rows:

print(row)

except Exception as e:

print(f"Error: {e}")

def calculate_room_rent(self):

print("We have the following rooms for you:")

print("1. Type A -> Rs 1000 per night")

print("2. Type B -> Rs 2000 per night")

print("3. Type C -> Rs 3000 per night")

print("4. Type D -> Rs 4000 per night")

try:

choice = int(input("Enter your choice: "))

nights = int(input("For how many nights did you stay: "))

rates = {1: 1000, 2: 2000, 3: 3000, 4: 4000}

if choice in rates:

rent = rates[choice] * nights

print(f"Your total room rent is Rs {rent}\n")

return rent

else:

print("Invalid room choice. Try again.")

return 0

except ValueError:

print("Invalid input. Please enter numbers only.")

return 0
def view_restaurant_menu(self):

try:

print("Restaurant menu:")

self.mycursor.execute("SELECT * FROM restaurent")

rows = self.mycursor.fetchall()

for row in rows:

print(row)

except Exception as e:

print(f"Error: {e}")

def order_item(self):

self.view_restaurant_menu()

menu = {

1: ("Tea", 10), 2: ("Coffee", 10), 3: ("Colddrink", 20),

4: ("Samosa", 10), 5: ("Sandwich", 50), 6: ("Dhokla", 30),

7: ("Kachori", 10), 8: ("Milk", 20), 9: ("Noodles", 50),

10: ("Pasta", 50)

try:

choice = int(input("Enter your choice from the menu: "))

if choice in menu:

quantity = int(input(f"Enter quantity for {menu[choice][0]}: "))

cost = menu[choice][1] * quantity

self.restaurant_bill += cost

print(f"Your amount for {menu[choice][0]} is Rs {cost}\n")

else:

print("Invalid choice. Please try again.")


except ValueError:

print("Invalid input. Please enter numbers only.")

def calculate_laundry_bill(self):

try:

clothes = int(input("Enter the number of clothes for laundry: "))

self.laundry_bill = clothes * 10

print(f"Your laundry bill is Rs {self.laundry_bill}\n")

except ValueError:

print("Invalid input. Please enter a number.")

def generate_bill(self):

customer_name = input("Enter customer name: ")

print("\n--- Final Bill ---")

print(f"Customer Name: {customer_name}")

print(f"Restaurant Bill: Rs {self.restaurant_bill}")

print(f"Laundry Bill: Rs {self.laundry_bill}")

# Room rent can be included by calling calculate_room_rent() before this step

print("Thank you for staying with us!\n")

def menu(self):

while True:

print("\n--- Hotel Management System ---")

print("1. Register Customer")

print("2. View Room Types")

print("3. Calculate Room Rent")

print("4. View Restaurant Menu")

print("5. Order from Restaurant")

print("6. Calculate Laundry Bill")


print("7. Generate Final Bill")

print("8. Exit")

try:

choice = int(input("Enter your choice: "))

if choice == 1:

self.register_customer()

elif choice == 2:

self.view_room_types()

elif choice == 3:

self.calculate_room_rent()

elif choice == 4:

self.view_restaurant_menu()

elif choice == 5:

self.order_item()

elif choice == 6:

self.calculate_laundry_bill()

elif choice == 7:

self.generate_bill()

elif choice == 8:

print("Exiting the system. Goodbye!")

break

else:

print("Invalid choice. Please try again.")

except ValueError:

print("Invalid input. Please enter a number.")

if __name__ == "__main__":
system = HotelManagementSystem()

system.menu()

You might also like