Question

Hi I want to make a function which will take a list and return a print out which shows the element number and the corresponding element in two columns.

Here is my stab at it:

printList(aList):
    """ Prints the current list.
    """
    print ('%3d %5.2f' % (i, aList[i]))

I get an error saying global i is not defined but I'm not sure how to define it.

Thank you in advance for your help!

Was it helpful?

Solution

well the i is really not defined. you are missing the loop

for i in range(len(aList)):
    ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top