문제

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!

도움이 되었습니까?

해결책

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

for i in range(len(aList)):
    ...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top