IndexError: list index out of range - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: IndexError: list index out of range (/thread-6281.html) |
IndexError: list index out of range - BoaCoder3 - Nov-13-2017 I'm trying to make a program that can work out a mathematical ratio problem and then take the square root of the answer. To achieve the multiplication part i'm trying to make empty lists to which i add the numbers the user enters to define the ratio, then multiplying the list elements with each other. However, when i tried to run the program, this is what i got: this is the program: def data_procesing(): while True: first_set = raw_input('first_set: ') for i in xrange(1, 2): parameters = [] parameters.append(first_set) a = parameters[0] * parameters[1] print a data_procesing()First i had the parameters = [] loop outside the function so i thought this might be a scope problem, so i put it inside the for loop, however, that didn't work either, Can anybody please tell me what i'm doing wrong? is it perhaps impossible to multiply list elements like i did? RE: IndexError: list index out of range - stranac - Nov-13-2017 parameters = [] parameters.append(first_set)At this point, the list only has one element ( first_set ).Trying to access its second element ( parameters[1] ) results in IndexError .
RE: IndexError: list index out of range - BoaCoder3 - Nov-14-2017 Oh yes of course, what was i thinking, thanks a million! |