0
0
Goprogramming~10 mins

Arithmetic operators in Go - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add two numbers and print the result.

Go
package main

import "fmt"

func main() {
    sum := 5 [1] 3
    fmt.Println(sum)
}
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
2fill in blank
medium

Complete the code to find the remainder when 10 is divided by 3.

Go
package main

import "fmt"

func main() {
    remainder := 10 [1] 3
    fmt.Println(remainder)
}
Drag options to blanks, or click blank then click option'
A%
B+
C*
D/
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using division instead of modulus.
3fill in blank
hard

Fix the error in the code to multiply two numbers correctly.

Go
package main

import "fmt"

func main() {
    product := 4 [1] 5
    fmt.Println(product)
}
Drag options to blanks, or click blank then click option'
A*
B-
C+
D/
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using addition or division instead of multiplication.
4fill in blank
hard

Fill both blanks to create a map of words to their lengths for words longer than 3 characters.

Go
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)
}
Drag options to blanks, or click blank then click option'
A>
Bword
Clen(word)
D<
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '<' instead of '>' for length comparison.
Assigning the word instead of its length.
5fill in blank
hard

Fill all three blanks to create a map with uppercase keys and values greater than 2.

Go
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)
}
Drag options to blanks, or click blank then click option'
Astrings.ToUpper(k)
Bv
C>
Dk
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using the key instead of uppercase key.
Using '<' instead of '>' in condition.