Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
โ Incorrect
The + operator adds two numbers together.
2fill in blank
mediumComplete 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using division instead of modulus.
โ Incorrect
The % operator gives the remainder of division.
3fill in blank
hardFix 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using addition or division instead of multiplication.
โ Incorrect
The * operator multiplies two numbers.
4fill in blank
hardFill 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using '<' instead of '>' for length comparison.
Assigning the word instead of its length.
โ Incorrect
The condition len(word) > 3 checks word length. The value len(word) stores the length.
5fill in blank
hardFill 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using the key instead of uppercase key.
Using '<' instead of '>' in condition.
โ Incorrect
We check if v > 2. Then store the value v with the uppercase key strings.ToUpper(k).