add: exercises and quiz for appending and slicing

This commit is contained in:
Inanc Gumus
2019-01-30 16:47:30 +03:00
parent 1068a0b9cd
commit 8ec394bc10
23 changed files with 928 additions and 63 deletions

View File

@ -0,0 +1,40 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import (
"fmt"
"strconv"
"strings"
)
func main() {
data := "2 4 6 1 3 5"
splitted := strings.Fields(data)
var nums []int
for _, s := range splitted {
n, _ := strconv.Atoi(s)
nums = append(nums, n)
}
// rest of the code for this exercise
fmt.Println("nums :", nums)
evens, odds := nums[:3], nums[3:]
fmt.Println("evens :", evens)
fmt.Println("odds :", odds)
fmt.Println("middle :", nums[2:4])
fmt.Println("first 2 :", nums[:2])
fmt.Println("last 2 :", nums[len(nums)-2:])
fmt.Println("evens last 1:", evens[len(evens)-1:])
fmt.Println("odds last 2 :", evens[len(evens)-2:])
}