Ask Your Question
1

Summing primes, cannot convert to int

asked 2015-06-19 15:33:10 +0100

Oderyn gravatar image

What can I do so that the following code works:

sage: var('k')
sage: sum(nth_prime(k),k,1,10)
ValueError: cannot convert k to int

Thanks in advance!

edit retag flag offensive close merge delete

Comments

The reason this doesn't work while sum(x^2,x,1,10) does is because nth_prime isn't a symbolic expression, it's just a random Sage function. nth_prime(x) already fails all by itself.

kcrisman gravatar imagekcrisman ( 2015-06-19 16:02:08 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-06-19 15:52:23 +0100

slelievre gravatar image

Don't involve symbolic variables.

Try this instead:

sage: sum(nth_prime(k) for k in (1 .. 10))
129
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-06-19 15:33:10 +0100

Seen: 932 times

Last updated: Jun 19 '15