Hi,
I am trying to execute the following code, got from this forum:
class TestIndexInArray:
def __init__(self, arr):
'''
@param arr: array to be tested
'''
self.arr = arr
def printItemsIndex(self):
'''
Prints the index of each item in a given array
'''
# message to tell us when the function was called
print(f'Print indexes for {self.arr}:')
for i in self.arr:
# find the index of i in arr
itemIndex = self.arr.index(i)
print(itemIndex)
print('\n')
def findItemAtIndex(self, index):
'''
@param index: refers to the location of the item in the array
'''
print(f'Item at {index} in {self.arr}:')
try:
print(self.arr[index])
except IndexError:
print(f'> error: index at {index} does not exist')
print('\n')
if __name__ =="__main__":
def header(num):
print(f'Test #{num}\n' + '='*40 + '\n')
header(1)
arr_one = TestIndexInArray([4, 9, 12, 3, 5, 24])
arr_one.printItemsIndex()
arr_one.findItemAtIndex(0)
arr_one.findItemAtIndex(2)
arr_one.findItemAtIndex(5)
arr_one.findItemAtIndex(6)
header(2)
arr_two = TestIndexInArray([])
arr_two.printItemsIndex()
arr_two.findItemAtIndex(0)
I am getting following errors:
File “/home/zulfi/PycharmProjects/Classes/exceptionProg.py”, line 3
‘’’
^
TabError: inconsistent use of tabs and spaces in indentationProcess finished with exit code 1
Somebody please guide me.
Zulfi.