Complete the code to check if two bookings overlap.
def is_conflict(booking1, booking2): return booking1.end_time [1] booking2.start_time
Two bookings conflict if the end time of the first booking is after the start time of the second booking.
Complete the code to add a booking only if no conflicts exist.
def add_booking(bookings, new_booking): for b in bookings: if is_conflict(b, new_booking): return False bookings.append([1]) return True
We append the new booking to the list only if no conflicts are found.
Fix the error in the conflict check to correctly detect overlapping bookings.
def is_conflict(booking1, booking2): return booking1.start_time [1] booking2.end_time and booking1.end_time [2] booking2.start_time
Two bookings overlap if booking1 starts before booking2 ends and booking1 ends after booking2 starts.
Fill both blanks to create a function that returns all conflicting bookings for a new booking.
def find_conflicts(bookings, new_booking): conflicts = [] for b in bookings: if b.start_time [1] new_booking.end_time and b.end_time [2] new_booking.start_time: conflicts.append(b) return conflicts
We check if existing booking starts before new booking ends and ends after new booking starts to find conflicts.
Fill all three blanks to create a dictionary comprehension that maps booking IDs to their durations for bookings longer than 1 hour.
durations = {b.id: (b.end_time - b.start_time).total_seconds() / 3600 for b in bookings if (b.end_time - b.start_time) [1] [2] and b.id [3] None}We filter bookings longer than 1 hour and ensure booking ID is not None.