# adding global variable in colab cause indent error

I’m trying to add a global variable to quicksort algorithm in colab. It works fine without the global variable ‘r’ but when I introduce it, I receive nonsense error of indention. but indention is correct. pls help.

``````    # Quicksort Sort
r=0
def partition(array, low, high):
global r
pivot = array[high]
i = low - 1
for j in range(low, high):
if array[j] <= pivot:
i = i + 1
(array[i], array[j]) = (array[j], array[i])
r=r+1
(array[i + 1], array[high]) = (array[high], array[i + 1])
r=r+1
return i + 1

def quickSort(array, low, high):
if low < high:
pi = partition(array, low, high)
quickSort(array, low, pi - 1)
quickSort(array, pi + 1, high)

data = [7,1,3,2,4,5,6]
print("Unsorted Array")
print(data)
size = len(data)
quickSort(data, 0, size - 1)
print('Sorted Array in Ascending Order:')
print(data,r)

```
the error:
``` File "<tokenize>", line 11
r=r+1
^
IndentationError: unindent does not match any outer indentation level
```
``````

### >Solution :

Indentation correction.

``````r=0
def partition(array, low, high):
global r
pivot=array[high]
i=low-1
for j in range(low, high):
if array[j] <= pivot:
i = i + 1
(array[i], array[j]) = (array[j], array[i])
r=r+1
(array[i + 1], array[high]) = (array[high], array[i + 1])
r=r+1
return i + 1

def quickSort(array, low, high):
if low < high:
pi = partition(array, low, high)
quickSort(array, low, pi - 1)
quickSort(array, pi + 1, high)

data = [7,1,3,2,4,5,6]
print("Unsorted Array")
print(data)
size = len(data)
quickSort(data, 0, size - 1)
print('Sorted Array in Ascending Order:')
print(data,r)
``````

Output:

``````Unsorted Array
[7, 1, 3, 2, 4, 5, 6]
Sorted Array in Ascending Order:
[1, 2, 3, 4, 5, 6, 7] 19
``````