Ask Your Question
1

What it means "TypeError: 'list' object is not callable"?

asked 2014-11-22 12:22:21 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

1) For example, how can I extract the divisors < 10 from the list divisors(n) ? I try to create a def with S=sum(d(i)) , d(i) verifying d(i)<10, but I get that TypeError

2) More generally, how can I do sum(d(i) with condition d(i)<10) ?

3) Where can I find a reference document for SAGE and an elementary tutorial?

Thanks

edit retag flag offensive close merge delete

Comments

I do not see the link between the title of the post and the three questions above...

vdelecroix gravatar imagevdelecroix ( 2014-11-22 23:37:57 -0600 )edit

You are right, I forgot to make clear that I had that error text because I was looking for a conditioned sum. Anyway the given answer guessed what I was meaning. Sorry

logomath gravatar imagelogomath ( 2014-11-24 08:39:40 -0600 )edit

Then, it would be helpful for other people looking for help if you change the title.

vdelecroix gravatar imagevdelecroix ( 2014-11-25 14:52:49 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-11-22 14:03:10 -0600

updated 2014-11-22 14:08:47 -0600

To extract the divisors less than 10, you can do this:

sage: k = 720
sage: sum(d for d in k.divisors() if d < 10)

See this tutorial.

The error you got is probably because of the following:

If you defined d as

sage: d = divisors(k)

Then d is a list. You can extract element number i of d as d[i], but you cannot do d(i) which would be "calling the function d with argument i". Sage tells you d is not "callable".

If you want to sum the first 10 divisors, do:

sage: sum(d[i] for i in range(10))

or

sage: sum(d[:10])
edit flag offensive delete link more

Comments

Thank you so much!

logomath gravatar imagelogomath ( 2014-11-22 15:32:57 -0600 )edit

If this answered your question, don't forget to accept it so that someone else coming to this forum sees quickly that it has an accepted, correct answer. And have fun learning more Python and Sage - it's fun to see how elegantly many such problems can be solved!

kcrisman gravatar imagekcrisman ( 2014-11-22 20:34:22 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-11-22 12:22:21 -0600

Seen: 2,346 times

Last updated: Nov 22 '14