I want to find sum of prime numbers ina given range but in cant callback my sum fuction please help me with it

package main

import (

func prime(x, y int) []int{
z := []int{}
for i := x; i < y; i++ {
for j := 2; j < i; j++ {
if i%j == 0 {
} else {
z = append(z, i)
return z
func sum(xi []int)int {
sum := 0
for _, v := range xi {
sum += v
return sum
func main() {

s := prime(10, 100)


Try using this method: https://play.golang.org/p/qsSIvlvfSv1

1 Like

thank you very much

can we make sum as a separate function

Hi. I made a small guide how to post code on this forum. It will make the code easier to read. How to post code on this forum

Edit based on code posted by Curtis Allyn Green. https://play.golang.org/p/OkHWY9LeJ4O

Nice that you put it in go playground :blush: The error in that code is that in the last example is sum called with 10 for both arguments sum(10, 10) instead of sum(10, 100) or something similar.