Complete the code to add two numbers and print the result.
package main import "fmt" func main() { sum := 5 [1] 3 fmt.Println(sum) }
The + operator adds two numbers together.
Complete the code to find the remainder when 10 is divided by 3.
package main import "fmt" func main() { remainder := 10 [1] 3 fmt.Println(remainder) }
The % operator gives the remainder of division.
Fix the error in the code to multiply two numbers correctly.
package main import "fmt" func main() { product := 4 [1] 5 fmt.Println(product) }
The * operator multiplies two numbers.
Fill both blanks to create a map of words to their lengths for words longer than 3 characters.
package main import "fmt" func main() { words := []string{"go", "code", "fun", "learn"} lengths := map[string]int{} for _, word := range words { if len(word) [1] 3 { lengths[word] = [2] } } fmt.Println(lengths) }
The condition len(word) > 3 checks word length. The value len(word) stores the length.
Fill all three blanks to create a map with uppercase keys and values greater than 2.
package main import ( "fmt" "strings" ) func main() { data := map[string]int{"go": 1, "code": 4, "fun": 3} result := map[string]int{} for k, v := range data { if v [3] 2 { result[[1]] = [2] } } fmt.Println(result) }
We check if v > 2. Then store the value v with the uppercase key strings.ToUpper(k).
