Challenge - 5 Problems
Go Import Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of importing and using fmt package
What is the output of this Go program?
Go
package main import "fmt" func main() { fmt.Println("Hello, Go!") }
Attempts:
2 left
💡 Hint
Look at what fmt.Println prints to the screen.
✗ Incorrect
The fmt package's Println function prints the string with a newline. So the output is exactly "Hello, Go!".
❓ Predict Output
intermediate2:00remaining
Output when importing multiple packages
What is the output of this Go program?
Go
package main import ( "fmt" "math" ) func main() { fmt.Println(int(math.Sqrt(16))) }
Attempts:
2 left
💡 Hint
math.Sqrt returns a float64. Casting to int truncates decimals.
✗ Incorrect
math.Sqrt(16) returns 4.0 as float64. Casting to int converts it to 4. So fmt.Println prints 4.
❓ Predict Output
advanced2:00remaining
Output when importing a package with alias
What is the output of this Go program?
Go
package main import f "fmt" func main() { f.Println("Alias import works!") }
Attempts:
2 left
💡 Hint
The alias f replaces fmt in this program.
✗ Incorrect
The import alias f allows calling fmt functions using f. So f.Println prints the string correctly.
❓ Predict Output
advanced2:00remaining
Output when importing a package but not using it
What happens when you run this Go program?
Go
package main import "fmt" func main() { // fmt package is imported but not used }
Attempts:
2 left
💡 Hint
Go does not allow unused imports.
✗ Incorrect
Go compiler requires all imported packages to be used. Since fmt is imported but not used, it causes a compilation error.
🧠 Conceptual
expert2:00remaining
Understanding blank identifier import
What is the effect of importing a package using the blank identifier (_) in Go?
Attempts:
2 left
💡 Hint
Think about why you would import a package but never call its functions directly.
✗ Incorrect
Using _ as the import alias imports the package only for its initialization side effects, like running init functions, without exposing its exported names.