Python: IndexError: list index out of range – trying to count two numbers from list in a for loop

I´m trying to write a code in python, that should make an arithmetic average from a numbers in list – The user inputs numbers that are converted into the list as integers, then I use for loop to count the amount of numbers in list, this I save to variable, after that I want to… Read More Python: IndexError: list index out of range – trying to count two numbers from list in a for loop

Why am I getting IndexError: list index out of range error even though I have a proper list

with open(‘Input’,’r’) as f: while len(a)>0: a=f.readline() #I am going to search for a command to execute in the txt file w_in_line=a.split(‘,’) #words in line command_word_box=w_in_line[0].split()#I took the command word out of the line command_word=str(command_word_box[0]) pat_name=w_in_line[0].replace(command_word,”) w_in_line[0]=pat_name for word in command_word_box: #searching for commands if word==’create’: create (w_in_line) else: continue The text file is: a… Read More Why am I getting IndexError: list index out of range error even though I have a proper list

Index error in binary search in an infinite sorted array

The program gives IndexError: list index out of range in binary search in the infinite sorted array when the element does not exist or is too large def binarySearch(l,ele,low=0,high=None): if(high==None): high=len(l)-1 if(low>high): return -1 mid= int((low+high)/2) pEle = l[mid] if(pEle==ele): return mid elif(pEle>ele): return binarySearch(l,ele,low,mid-1) else: return binarySearch(l,ele,mid+1,high) # This is a function that searches… Read More Index error in binary search in an infinite sorted array