0
0
Goprogramming~20 mins

Importing packages in Go - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Go Import Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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!")
}
AHello, Go!
Bfmt.Println("Hello, Go!")
CHello Go
DCompilation error
Attempts:
2 left
💡 Hint
Look at what fmt.Println prints to the screen.
Predict Output
intermediate
2: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)))
}
ACompilation error
B16
C4
D0
Attempts:
2 left
💡 Hint
math.Sqrt returns a float64. Casting to int truncates decimals.
Predict Output
advanced
2: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!")
}
ACompilation error: alias import not allowed
Bf.Println("Alias import works!")
CCompilation error: undefined f
DAlias import works!
Attempts:
2 left
💡 Hint
The alias f replaces fmt in this program.
Predict Output
advanced
2: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
}
ACompilation error: imported and not used: "fmt"
BProgram runs with no output
CRuntime error
DWarning but runs successfully
Attempts:
2 left
💡 Hint
Go does not allow unused imports.
🧠 Conceptual
expert
2:00remaining
Understanding blank identifier import
What is the effect of importing a package using the blank identifier (_) in Go?
AIt imports the package and renames all its exported functions to start with _.
BIt imports the package solely for its side effects without making its exported names available.
CIt causes a compilation error because _ is not a valid alias.
DIt imports the package and allows using its exported names with the _ prefix.
Attempts:
2 left
💡 Hint
Think about why you would import a package but never call its functions directly.