7 months ago
22 lines398 B
package main | |
| |
import "fmt" | |
| |
func average(xs []float64) float64 { | |
sum := 0.0 | |
for _, x := range xs { | |
sum += x | |
} | |
return sum / float64(len(xs)) | |
} | |
| |
func main() { | |
scores := map[string][]float64{"ana": {7, 9}, "ben": {5, 8, 10}} | |
for name, s := range scores { | |
fmt.Printf("%s: %.1f\n", name, average(s)) | |
} | |
} | |
| |
// Questions? Ask in the course forum. | |
| |
// See the lesson README for what to try next. |