def has_cycle(head): slow = head fast = head while fast != None: slow = slow.next if fast.next != None: fast …