Ask Your Question
1

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

asked 2014-11-22 19:22:21 +0100

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-23 06:37:57 +0100 )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 15:39:40 +0100 )edit

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

vdelecroix gravatar imagevdelecroix ( 2014-11-25 21:52:49 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-11-22 21:03:10 +0100

slelievre gravatar image

updated 2014-11-22 21:08:47 +0100

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 22:32:57 +0100 )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-23 03:34:22 +0100 )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 19:22:21 +0100

Seen: 6,466 times

Last updated: Nov 22 '14