buggy_code:
def binary_search(arr, target):
    left, right = 0, len(arr)
    while left < right:
        mid = (left + right) // 2
        if arr[mid] == target:
            return mid
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid
    return -1

original_code:
def binary_search(arr, target):
    left, right = 0, len(arr) - 1
    while left <= right:
        mid = (left + right) // 2
        if arr[mid] == target:
            return mid
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1

initial_error: IndexError: list index out of range on line 5


buggy_code:
def is_palindrome(s):
    return s == s[::-1] and len(s) > 0

initial_error: AssertionError: is_palindrome('') expected True, got False

input: racecar

input: hello

input: a


buggy_code:
def find_max(nums):
    max_val = nums[0]
    for i in range(1, len(nums) + 1):
        if nums[i] > max_val:
            max_val = nums[i]
    return max_val

original_code:
def find_max(nums):
    max_val = nums[0]
    for i in range(1, len(nums)):
        if nums[i] > max_val:
            max_val = nums[i]
    return max_val

initial_error: IndexError: list index out of range on line 4


buggy_code:
def count_vowels(s):
    count = 0
    for ch in s:
        if ch in 'aeiou':
            count += 1
    return count

original_code:
def count_vowels(s):
    count = 0
    for ch in s.lower():
        if ch in 'aeiou':
            count += 1
    return count

initial_error: AssertionError: count_vowels('Hello') expected 2, got 1

input: hello

input: Hello

input: AEIOU

input: xyz


buggy_code:
def sum_list(nums):
    total = 0
    for i in range(len(nums) - 1):
        total += nums[i]
    return total

original_code:
def sum_list(nums):
    total = 0
    for i in range(len(nums)):
        total += nums[i]
    return total

initial_error: AssertionError: sum_list([1,2,3]) expected 6, got 3


buggy_code:
def is_sorted(lst):
    for i in range(len(lst) - 1):
        if lst[i] > lst[i + 1]:
            return True
    return False

original_code:
def is_sorted(lst):
    for i in range(len(lst) - 1):
        if lst[i] > lst[i + 1]:
            return False
    return True

initial_error: AssertionError: is_sorted([1,2,3]) expected True, got False


function_name: factorial

buggy_code:
def factorial(n):
    if n == 0:
        return 0
    result = 1
    for i in range(1, n + 1):
        result *= i
    return result

original_code:
def factorial(n):
    if n == 0:
        return 1
    result = 1
    for i in range(1, n + 1):
        result *= i
    return result

initial_error: AssertionError: factorial(0) expected 1, got 0

function: factorial


buggy_code:
def is_even(n):
    return n % 2 != 0

original_code:
def is_even(n):
    return n % 2 == 0

initial_error: AssertionError: is_even(4) expected True, got False