Summing primes, cannot convert to int
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!
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!
Don't involve symbolic variables.
Try this instead:
sage: sum(nth_prime(k) for k in (1 .. 10))
129
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2015-06-19 15:33:10 +0100
Seen: 922 times
Last updated: Jun 19 '15
Difference between sum and for loop
Sage showed "TypeError: need a summation variable" when i used sum function with for loop
How to evaluate the infinite sum of 1/(2^n-1) over all positive integers?
Help finding expected value of sum of random variables
how to sum up the function over all permutations of variables in associative non-commutative algebra
The reason this doesn't work while
sum(x^2,x,1,10)
does is becausenth_prime
isn't a symbolic expression, it's just a random Sage function.nth_prime(x)
already fails all by itself.