zak100 Posted March 14, 2020 Share Posted March 14, 2020 Hi, I have got the following program: 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: Quote File “/home/zulfi/PycharmProjects/Classes/exceptionProg.py”, line 3 ‘’’ ^ TabError: inconsistent use of tabs and spaces in indentation Process finished with exit code 1 Somebody please guide me. Zulfi. Link to comment Share on other sites More sharing options...
fiveworlds Posted March 14, 2020 Share Posted March 14, 2020 In python you must use either tabs or spaces for indentation not both. It is an annoying feature of python if you are using notepad++ you can "view>show symbol>show white space and tabs" 1 Link to comment Share on other sites More sharing options...
Strange Posted March 14, 2020 Share Posted March 14, 2020 You can configure your editor to use only spaces (and, in most cases, to convert existing tabs to spaces) 1 Link to comment Share on other sites More sharing options...
zak100 Posted March 15, 2020 Author Share Posted March 15, 2020 Hi @fiveWorlds and @Strange, Thanks for helping me. I tried cutting and then pasting on notepad and then pasting it back on the pycharm but sorry it did not work. However when I clicked the bulb it asked me to convert the tabs into spaces and this worked. Thanks a lot. Zulfi. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now