prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Global variable should not using in class method
  ### Repository commit
  
  9caf4784aada17dc75348f77cc8c356df503c0f3
  
  ### Python version (python --version)
  
  python3.11
  
  ### Dependencies version (pip freeze)
  
  #nop 
  
  ### Expected behavior
  
  Hi, guys. I come across one global variable that used in class method. I think using instance attribute would be better !
  ```python
      def show_data(self):
          show_list = []
          for i in range(1, N + 1):  ==> should using self.N instead of N !
              show_list += [self.query(i, i)]
          print(show_list)
  ```
  [source](https://github.com/TheAlgorithms/Python/blob/master/data_structures/binary_tree/segment_tree.py#L101)
  
  
  
  ### Actual behavior
  
  ```python
      def show_data(self):
          show_list = []
          for i in range(1, self.N + 1):  
              show_list += [self.query(i, i)]
          print(show_list)
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `data_structures/binary_tree/segment_tree.py`
  Content:
  ```
  1 import math
  2 
  3 
  4 class SegmentTree:
  5     def __init__(self, a):
  6         self.A = a
  7         self.N = len(self.A)
  8         self.st = [0] * (
  9             4 * self.N
  10         )  # approximate the overall size of segment tree with array N
  11         if self.N:
  12             self.build(1, 0, self.N - 1)
  13 
  14     def left(self, idx):
  15         """
  16         Returns the left child index for a given index in a binary tree.
  17 
  18         >>> s = SegmentTree([1, 2, 3])
  19         >>> s.left(1)
  20         2
  21         >>> s.left(2)
  22         4
  23         """
  24         return idx * 2
  25 
  26     def right(self, idx):
  27         """
  28         Returns the right child index for a given index in a binary tree.
  29 
  30         >>> s = SegmentTree([1, 2, 3])
  31         >>> s.right(1)
  32         3
  33         >>> s.right(2)
  34         5
  35         """
  36         return idx * 2 + 1
  37 
  38     def build(self, idx, l, r):  # noqa: E741
  39         if l == r:
  40             self.st[idx] = self.A[l]
  41         else:
  42             mid = (l + r) // 2
  43             self.build(self.left(idx), l, mid)
  44             self.build(self.right(idx), mid + 1, r)
  45             self.st[idx] = max(self.st[self.left(idx)], self.st[self.right(idx)])
  46 
  47     def update(self, a, b, val):
  48         """
  49         Update the values in the segment tree in the range [a,b] with the given value.
  50 
  51         >>> s = SegmentTree([1, 2, 3, 4, 5])
  52         >>> s.update(2, 4, 10)
  53         True
  54         >>> s.query(1, 5)
  55         10
  56         """
  57         return self.update_recursive(1, 0, self.N - 1, a - 1, b - 1, val)
  58 
  59     def update_recursive(self, idx, l, r, a, b, val):  # noqa: E741
  60         """
  61         update(1, 1, N, a, b, v) for update val v to [a,b]
  62         """
  63         if r < a or l > b:
  64             return True
  65         if l == r:
  66             self.st[idx] = val
  67             return True
  68         mid = (l + r) // 2
  69         self.update_recursive(self.left(idx), l, mid, a, b, val)
  70         self.update_recursive(self.right(idx), mid + 1, r, a, b, val)
  71         self.st[idx] = max(self.st[self.left(idx)], self.st[self.right(idx)])
  72         return True
  73 
  74     def query(self, a, b):
  75         """
  76         Query the maximum value in the range [a,b].
  77 
  78         >>> s = SegmentTree([1, 2, 3, 4, 5])
  79         >>> s.query(1, 3)
  80         3
  81         >>> s.query(1, 5)
  82         5
  83         """
  84         return self.query_recursive(1, 0, self.N - 1, a - 1, b - 1)
  85 
  86     def query_recursive(self, idx, l, r, a, b):  # noqa: E741
  87         """
  88         query(1, 1, N, a, b) for query max of [a,b]
  89         """
  90         if r < a or l > b:
  91             return -math.inf
  92         if l >= a and r <= b:
  93             return self.st[idx]
  94         mid = (l + r) // 2
  95         q1 = self.query_recursive(self.left(idx), l, mid, a, b)
  96         q2 = self.query_recursive(self.right(idx), mid + 1, r, a, b)
  97         return max(q1, q2)
  98 
  99     def show_data(self):
  100         show_list = []
  101         for i in range(1, N + 1):
  102             show_list += [self.query(i, i)]
  103         print(show_list)
  104 
  105 
  106 if __name__ == "__main__":
  107     A = [1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]
  108     N = 15
  109     segt = SegmentTree(A)
  110     print(segt.query(4, 6))
  111     print(segt.query(7, 11))
  112     print(segt.query(7, 12))
  113     segt.update(1, 3, 111)
  114     print(segt.query(1, 15))
  115     segt.update(7, 8, 235)
  116     segt.show_data()
  117
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/data_structures/binary_tree/segment_tree.py b/data_structures/binary_tree/segment_tree.py
  --- a/data_structures/binary_tree/segment_tree.py
  +++ b/data_structures/binary_tree/segment_tree.py
  @@ -98,7 +98,7 @@
   
       def show_data(self):
           show_list = []
  -        for i in range(1, N + 1):
  +        for i in range(1, self.N + 1):
               show_list += [self.query(i, i)]
           print(show_list)
  
verification_info: {"golden_diff": "diff --git a/data_structures/binary_tree/segment_tree.py b/data_structures/binary_tree/segment_tree.py\n--- a/data_structures/binary_tree/segment_tree.py\n+++ b/data_structures/binary_tree/segment_tree.py\n@@ -98,7 +98,7 @@\n \n     def show_data(self):\n         show_list = []\n-        for i in range(1, N + 1):\n+        for i in range(1, self.N + 1):\n             show_list += [self.query(i, i)]\n         print(show_list)\n", "issue": "Global variable should not using in class method\n### Repository commit\n\n9caf4784aada17dc75348f77cc8c356df503c0f3\n\n### Python version (python --version)\n\npython3.11\n\n### Dependencies version (pip freeze)\n\n#nop \n\n### Expected behavior\n\nHi, guys. I come across one global variable that used in class method. I think using instance attribute would be better !\r\n```python\r\n    def show_data(self):\r\n        show_list = []\r\n        for i in range(1, N + 1):  ==> should using self.N instead of N !\r\n            show_list += [self.query(i, i)]\r\n        print(show_list)\r\n```\r\n[source](https://github.com/TheAlgorithms/Python/blob/master/data_structures/binary_tree/segment_tree.py#L101)\r\n\r\n\n\n### Actual behavior\n\n```python\r\n    def show_data(self):\r\n        show_list = []\r\n        for i in range(1, self.N + 1):  \r\n            show_list += [self.query(i, i)]\r\n        print(show_list)\r\n```\n", "before_files": [{"content": "import math\n\n\nclass SegmentTree:\n    def __init__(self, a):\n        self.A = a\n        self.N = len(self.A)\n        self.st = [0] * (\n            4 * self.N\n        )  # approximate the overall size of segment tree with array N\n        if self.N:\n            self.build(1, 0, self.N - 1)\n\n    def left(self, idx):\n        \"\"\"\n        Returns the left child index for a given index in a binary tree.\n\n        >>> s = SegmentTree([1, 2, 3])\n        >>> s.left(1)\n        2\n        >>> s.left(2)\n        4\n        \"\"\"\n        return idx * 2\n\n    def right(self, idx):\n        \"\"\"\n        Returns the right child index for a given index in a binary tree.\n\n        >>> s = SegmentTree([1, 2, 3])\n        >>> s.right(1)\n        3\n        >>> s.right(2)\n        5\n        \"\"\"\n        return idx * 2 + 1\n\n    def build(self, idx, l, r):  # noqa: E741\n        if l == r:\n            self.st[idx] = self.A[l]\n        else:\n            mid = (l + r) // 2\n            self.build(self.left(idx), l, mid)\n            self.build(self.right(idx), mid + 1, r)\n            self.st[idx] = max(self.st[self.left(idx)], self.st[self.right(idx)])\n\n    def update(self, a, b, val):\n        \"\"\"\n        Update the values in the segment tree in the range [a,b] with the given value.\n\n        >>> s = SegmentTree([1, 2, 3, 4, 5])\n        >>> s.update(2, 4, 10)\n        True\n        >>> s.query(1, 5)\n        10\n        \"\"\"\n        return self.update_recursive(1, 0, self.N - 1, a - 1, b - 1, val)\n\n    def update_recursive(self, idx, l, r, a, b, val):  # noqa: E741\n        \"\"\"\n        update(1, 1, N, a, b, v) for update val v to [a,b]\n        \"\"\"\n        if r < a or l > b:\n            return True\n        if l == r:\n            self.st[idx] = val\n            return True\n        mid = (l + r) // 2\n        self.update_recursive(self.left(idx), l, mid, a, b, val)\n        self.update_recursive(self.right(idx), mid + 1, r, a, b, val)\n        self.st[idx] = max(self.st[self.left(idx)], self.st[self.right(idx)])\n        return True\n\n    def query(self, a, b):\n        \"\"\"\n        Query the maximum value in the range [a,b].\n\n        >>> s = SegmentTree([1, 2, 3, 4, 5])\n        >>> s.query(1, 3)\n        3\n        >>> s.query(1, 5)\n        5\n        \"\"\"\n        return self.query_recursive(1, 0, self.N - 1, a - 1, b - 1)\n\n    def query_recursive(self, idx, l, r, a, b):  # noqa: E741\n        \"\"\"\n        query(1, 1, N, a, b) for query max of [a,b]\n        \"\"\"\n        if r < a or l > b:\n            return -math.inf\n        if l >= a and r <= b:\n            return self.st[idx]\n        mid = (l + r) // 2\n        q1 = self.query_recursive(self.left(idx), l, mid, a, b)\n        q2 = self.query_recursive(self.right(idx), mid + 1, r, a, b)\n        return max(q1, q2)\n\n    def show_data(self):\n        show_list = []\n        for i in range(1, N + 1):\n            show_list += [self.query(i, i)]\n        print(show_list)\n\n\nif __name__ == \"__main__\":\n    A = [1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]\n    N = 15\n    segt = SegmentTree(A)\n    print(segt.query(4, 6))\n    print(segt.query(7, 11))\n    print(segt.query(7, 12))\n    segt.update(1, 3, 111)\n    print(segt.query(1, 15))\n    segt.update(7, 8, 235)\n    segt.show_data()\n", "path": "data_structures/binary_tree/segment_tree.py"}], "after_files": [{"content": "import math\n\n\nclass SegmentTree:\n    def __init__(self, a):\n        self.A = a\n        self.N = len(self.A)\n        self.st = [0] * (\n            4 * self.N\n        )  # approximate the overall size of segment tree with array N\n        if self.N:\n            self.build(1, 0, self.N - 1)\n\n    def left(self, idx):\n        \"\"\"\n        Returns the left child index for a given index in a binary tree.\n\n        >>> s = SegmentTree([1, 2, 3])\n        >>> s.left(1)\n        2\n        >>> s.left(2)\n        4\n        \"\"\"\n        return idx * 2\n\n    def right(self, idx):\n        \"\"\"\n        Returns the right child index for a given index in a binary tree.\n\n        >>> s = SegmentTree([1, 2, 3])\n        >>> s.right(1)\n        3\n        >>> s.right(2)\n        5\n        \"\"\"\n        return idx * 2 + 1\n\n    def build(self, idx, l, r):  # noqa: E741\n        if l == r:\n            self.st[idx] = self.A[l]\n        else:\n            mid = (l + r) // 2\n            self.build(self.left(idx), l, mid)\n            self.build(self.right(idx), mid + 1, r)\n            self.st[idx] = max(self.st[self.left(idx)], self.st[self.right(idx)])\n\n    def update(self, a, b, val):\n        \"\"\"\n        Update the values in the segment tree in the range [a,b] with the given value.\n\n        >>> s = SegmentTree([1, 2, 3, 4, 5])\n        >>> s.update(2, 4, 10)\n        True\n        >>> s.query(1, 5)\n        10\n        \"\"\"\n        return self.update_recursive(1, 0, self.N - 1, a - 1, b - 1, val)\n\n    def update_recursive(self, idx, l, r, a, b, val):  # noqa: E741\n        \"\"\"\n        update(1, 1, N, a, b, v) for update val v to [a,b]\n        \"\"\"\n        if r < a or l > b:\n            return True\n        if l == r:\n            self.st[idx] = val\n            return True\n        mid = (l + r) // 2\n        self.update_recursive(self.left(idx), l, mid, a, b, val)\n        self.update_recursive(self.right(idx), mid + 1, r, a, b, val)\n        self.st[idx] = max(self.st[self.left(idx)], self.st[self.right(idx)])\n        return True\n\n    def query(self, a, b):\n        \"\"\"\n        Query the maximum value in the range [a,b].\n\n        >>> s = SegmentTree([1, 2, 3, 4, 5])\n        >>> s.query(1, 3)\n        3\n        >>> s.query(1, 5)\n        5\n        \"\"\"\n        return self.query_recursive(1, 0, self.N - 1, a - 1, b - 1)\n\n    def query_recursive(self, idx, l, r, a, b):  # noqa: E741\n        \"\"\"\n        query(1, 1, N, a, b) for query max of [a,b]\n        \"\"\"\n        if r < a or l > b:\n            return -math.inf\n        if l >= a and r <= b:\n            return self.st[idx]\n        mid = (l + r) // 2\n        q1 = self.query_recursive(self.left(idx), l, mid, a, b)\n        q2 = self.query_recursive(self.right(idx), mid + 1, r, a, b)\n        return max(q1, q2)\n\n    def show_data(self):\n        show_list = []\n        for i in range(1, self.N + 1):\n            show_list += [self.query(i, i)]\n        print(show_list)\n\n\nif __name__ == \"__main__\":\n    A = [1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]\n    N = 15\n    segt = SegmentTree(A)\n    print(segt.query(4, 6))\n    print(segt.query(7, 11))\n    print(segt.query(7, 12))\n    segt.update(1, 3, 111)\n    print(segt.query(1, 15))\n    segt.update(7, 8, 235)\n    segt.show_data()\n", "path": "data_structures/binary_tree/segment_tree.py"}]}