Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a package in Go.
Go
package [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fmt' as a package name instead of 'main'.
Trying to declare a function or variable instead of a package.
✗ Incorrect
In Go, every file starts with a package declaration. The main package is used for executable programs.
2fill in blank
mediumComplete the code to import the fmt package.
Go
import [1]fmt"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes or backticks instead of double quotes.
Using a colon instead of quotes.
✗ Incorrect
In Go, import paths are enclosed in double quotes "".
3fill in blank
hardFix the error in the function declaration by completing the code.
Go
func [1]() { fmt.Println("Hello, Go!") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Capitalizing 'Main' instead of 'main'.
Using 'func' or 'print' as function names.
✗ Incorrect
The entry point function in Go programs is main with a lowercase 'm'.
4fill in blank
hardFill both blanks to create a map of string keys to int values with a condition.
Go
ages := map[string]int{
"Alice": 30,
"Bob": 25,
"Carol": 27,
}
for name, age := range ages {
if age [1] 26 {
fmt.Println(name, "is older than", [2])
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the condition.
Printing the variable 'name' instead of 'age' for the age value.
✗ Incorrect
The condition checks if age is greater than 26, and prints the name and age.
5fill in blank
hardFill all three blanks to create a slice of strings and print each element.
Go
names := [][1]{"Anna", "Ben", "Cara"} for [2], [3] := range names { fmt.Println(index, name) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' instead of 'string' for the slice type.
Using incorrect variable names in the for loop.
✗ Incorrect
The slice holds strings, and the for loop uses index and name to iterate and print each element.