嘿伙计们我对python相对较新,我遇到了这个问题,我无法解决。 我需要创建一个python代码,其作用类似于酒店接待的调度程序。它必须在包含单个预订的列表中进行搜索。 这些具体的预订包含到达和离开日期,但我不知道如何检查和比较这些范围。我的房间数量有限,这是另一个标准。
rooms = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
booking = []
booking_id = 0
def make_booking():
bframe = Tk()
bframe.geometry('200x150+150+150')
bframe.title('New booking')
nameLabel = Label(bframe, text='Name').grid(row=0, column=0)
name = Entry(bframe)
name.grid(row=0, column=1)
ArrivalLabel = Label(bframe, text='Arrival in: DD.MM.YYYY').grid(row=2, column=0)
arrival = Entry(bframe)
arrival.grid(row=2, column=1)
deptLabel = Label(bframe, text='Departure in: DD.MM.YYYY').grid(row=3, column=0)
dept = Entry(bframe)
dept.grid(row=3, column=1)
def save_booking():
arrival = time.strptime(arrival.get(), "%d.%m.%y")
dept = time.strptime(dept.get(), "%d.%m.%y")
global booking_id
booking_id += 1
b = [booking_id, name.get(), arrival, dept]
booking.append(b)
else:
messagebox.showinfo(title="Whops", message="""
Something went wrong with your booking entry. Did you check the room availability?""")
bframe.destroy()
saveButton = Button(bframe, text="Save", command=save_booking).grid(row=4, column=0)
这是我的代码atm。其他情况来自我的旧版本有点工作,但没有检查某个日期范围的房间可用性
def save_booking():
b = (name.get(), room_number.get(), arrival.get(), dept.get())
if rooms[int(room_number.get())] == 0:
global booking_id
booking_id += 1
b.append(booking_id)
rooms[int(room_number.get())] = b
关于如何解决这个问题的任何想法?