On 5/16/12, Greg Christian <glchrist...@comcast.net> wrote:
> Can anyone tell me what I am doing wrong here. When trying to call the
> factors function from main with x = factors(Tn), getting the error message:
> “TypeError: 'int' object is not callable”? Any help would be appreciated.
> Thanks.
>
>
> def factors(n):
>     L = []
>     for i in range(1, int(n ** 0.5) + 1):
>         if (n % i == 0):
>             L.append(i)
>     return L
>
> def main():
>     factors = 0
>     counter = 0
>     L = []
>     while len(L) < 50:
>         counter += 1
>         L.append(counter)
>         Tn = sum(L)
>         x = factors(Tn)
>         #print x
>     print(sum(L))
>
>
> if __name__ == '__main__':
>     main()

You declared 'factors' as a variable on line 1 in main::

    factors = 0

This masks the call to the function 'factors'. You get the error because you
assigned factors an integer and you cannot 'call' an integer. The easiest
solution is to use another name for the variable 'factors' instead.

-Modulok-
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to