Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Hello, World!" in Go.
Go
package main import "fmt" func main() { fmt.[1]("Hello, World!") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using fmt.Print does not add a new line after printing.
Typo in function name like Printfln causes errors.
โ Incorrect
The fmt.Println function prints the text followed by a new line.
2fill in blank
mediumComplete the code to declare the main package in Go.
Go
[1] main
func main() {
// program starts here
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Writing 'func' instead of 'package' at the top.
Omitting the package declaration causes errors.
โ Incorrect
The package keyword declares the package name at the top of a Go file.
3fill in blank
hardFix the error in the function declaration to make it valid Go code.
Go
func [1]() { fmt.Println("Hello") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using uppercase 'Main' instead of 'main'.
Adding parentheses after the function name in declaration.
โ Incorrect
The main function must be named exactly main without parentheses in the declaration.
4fill in blank
hardFill both blanks to import the fmt package and print a message.
Go
package main import [1]"fmt"[2] func main() { fmt.Println("Welcome to Go!") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using square brackets instead of parentheses.
Using quotes alone without parentheses for multiple imports.
โ Incorrect
Use parentheses to import packages in a block: import ("fmt").
5fill in blank
hardFill all three blanks to create a map of string keys to int values with one entry.
Go
package main
func main() {
scores := map[[1]][2]{
"Alice": [3],
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using float64 instead of int for map values.
Using incorrect key type like int instead of string.
โ Incorrect
The map keys are strings, values are integers, and the value assigned is 100.