# 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!

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!

2

Don't involve symbolic variables.

Try this instead:

```
sage: sum(nth_prime(k) for k in (1 .. 10))
129
```

Asked: **
2015-06-19 08:33:10 -0500
**

Seen: **513 times**

Last updated: **Jun 19 '15**

Help finding expected value of sum of random variables

Difference between sum and for loop

Expanding summation with factorial

Summation of simbolic variables

how to sum up the function over all permutations of variables in associative non-commutative algebra

Help summing an infinite series

Summation with variables in limit

Sage showed "TypeError: need a summation variable" when i used sum function with for loop

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.

The reason this

doesn'twork 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.