python写一个旅游管理系统
时间: 2023-07-13 16:35:07 浏览: 92
好的,下面是一个简单的旅游管理系统的Python代码示例:
```python
class Tourist:
def __init__(self, name, age, gender, phone_number, email):
self.name = name
self.age = age
self.gender = gender
self.phone_number = phone_number
self.email = email
class TourPackage:
def __init__(self, name, places, days, cost):
self.name = name
self.places = places
self.days = days
self.cost = cost
class Booking:
def __init__(self, tourist, tour_package, booking_date):
self.tourist = tourist
self.tour_package = tour_package
self.booking_date = booking_date
class TourManagementSystem:
def __init__(self):
self.tourists = []
self.tour_packages = []
self.bookings = []
def add_tourist(self):
print("Enter tourist details:")
name = input("Name: ")
age = int(input("Age: "))
gender = input("Gender: ")
phone_number = input("Phone Number: ")
email = input("Email: ")
tourist = Tourist(name, age, gender, phone_number, email)
self.tourists.append(tourist)
print("Tourist added successfully.")
def display_tourists(self):
print("List of tourists:")
for tourist in self.tourists:
print("Name:", tourist.name)
print("Age:", tourist.age)
print("Gender:", tourist.gender)
print("Phone Number:", tourist.phone_number)
print("Email:", tourist.email)
print("")
def add_tour_package(self):
print("Enter tour package details:")
name = input("Name: ")
places = input("Places (separated by comma): ")
days = int(input("Number of days: "))
cost = float(input("Cost: "))
tour_package = TourPackage(name, places, days, cost)
self.tour_packages.append(tour_package)
print("Tour package added successfully.")
def display_tour_packages(self):
print("List of tour packages:")
for tour_package in self.tour_packages:
print("Name:", tour_package.name)
print("Places:", tour_package.places)
print("Number of days:", tour_package.days)
print("Cost:", tour_package.cost)
print("")
def book_tour(self):
print("Enter booking details:")
tourist_name = input("Tourist Name: ")
tour_package_name = input("Tour Package Name: ")
booking_date = input("Booking Date (DD/MM/YYYY): ")
tourist = next((t for t in self.tourists if t.name == tourist_name), None)
tour_package = next((tp for tp in self.tour_packages if tp.name == tour_package_name), None)
if tourist and tour_package:
booking = Booking(tourist, tour_package, booking_date)
self.bookings.append(booking)
print("Tour booked successfully.")
else:
print("Tourist or tour package not found.")
def display_bookings(self):
print("List of bookings:")
for booking in self.bookings:
print("Tourist Name:", booking.tourist.name)
print("Tour Package:", booking.tour_package.name)
print("Booking Date:", booking.booking_date)
print("")
tour_management_system = TourManagementSystem()
while True:
print("1. Add Tourist")
print("2. Display Tourists")
print("3. Add Tour Package")
print("4. Display Tour Packages")
print("5. Book Tour")
print("6. Display Bookings")
print("7. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
tour_management_system.add_tourist()
elif choice == 2:
tour_management_system.display_tourists()
elif choice == 3:
tour_management_system.add_tour_package()
elif choice == 4:
tour_management_system.display_tour_packages()
elif choice == 5:
tour_management_system.book_tour()
elif choice == 6:
tour_management_system.display_bookings()
elif choice == 7:
break
else:
print("Invalid choice. Please try again.")
```
这个程序使用了类来表示旅游者、旅游套餐和预订,并使用一个TourManagementSystem类来管理它们。用户可以使用菜单选项添加旅游者、旅游套餐和预订,以及查看它们的列表。
阅读全文