Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the "fmt" package.
Go
package main import [1] func main() { fmt.Println("Hello, Go!") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the quotes around the package name.
Importing the wrong package like "os" instead of "fmt".
✗ Incorrect
The "fmt" package is used for formatted I/O, including printing to the console.
2fill in blank
mediumComplete the code to import both "fmt" and "math" packages.
Go
package main import ( [1] "math" ) func main() { fmt.Println(math.Sqrt(16)) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the "fmt" package causes an error when calling fmt.Println.
Using incorrect package names.
✗ Incorrect
To use fmt.Println, you must import the "fmt" package along with "math".
3fill in blank
hardFix the error in the import statement to correctly import the "net/http" package.
Go
package main import ( "fmt" [1] ) func main() { resp, err := http.Get("http://example.com") if err != nil { fmt.Println(err) } fmt.Println(resp.Status) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes instead of double quotes.
Writing package names without quotes.
✗ Incorrect
Go import paths must be enclosed in double quotes.
4fill in blank
hardFill both blanks to import "fmt" and alias "math/rand" as "random".
Go
package main import ( [1] [2] ) func main() { fmt.Println(random.Intn(10)) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using alias syntax correctly.
Importing "math/rand" without alias when alias is needed.
✗ Incorrect
You import "fmt" normally and alias "math/rand" as "random" using the syntax: alias "package".
5fill in blank
hardFill all three blanks to import "fmt", alias "math/rand" as "random", and import "time" package.
Go
package main import ( [1] [2] [3] ) func main() { fmt.Println(random.Intn(100)) fmt.Println(time.Now()) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around package names.
Not aliasing "math/rand" correctly.
Missing one of the packages.
✗ Incorrect
Import "fmt" normally, alias "math/rand" as "random", and import "time" normally.