0
0
Goprogramming~10 mins

Why packages are used in Go - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the fmt package for printing.

Go
import [1]
Drag options to blanks, or click blank then click option'
A"fmt"
B"math"
C"os"
D"net/http"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a package unrelated to printing like math or os.
Forgetting the quotes around the package name.
2fill in blank
medium

Complete the code to declare the package name for this file.

Go
package [1]
Drag options to blanks, or click blank then click option'
Ahttp
Bmain
Cos
Dfmt
Attempts:
3 left
💡 Hint
Common Mistakes
Using package names like fmt or os which are standard libraries, not the main program.
Leaving out the package declaration.
3fill in blank
hard

Fix the error in the import statement to correctly import the math package.

Go
import [1]
Drag options to blanks, or click blank then click option'
A"math"
Bmath
C'math'
D<math>
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes or no quotes around the package name.
Using angle brackets which are not valid in Go imports.
4fill in blank
hard

Fill both blanks to create a function that uses the fmt package to print a message.

Go
func main() {
    [1].[2]("Hello, Go packages!")
}
Drag options to blanks, or click blank then click option'
Afmt
BPrintln
CPrint
Dmain
Attempts:
3 left
💡 Hint
Common Mistakes
Using Print instead of Println which does not add a newline.
Using main as a package name here.
5fill in blank
hard

Fill both blanks to create a package named utils with a function that returns the sum of two integers.

Go
package [1]

func Add(a int, b int) int {
    return a [2] b
}
Drag options to blanks, or click blank then click option'
Autils
B+
Dmain
Attempts:
3 left
💡 Hint
Common Mistakes
Using main as the package name here.
Adding extra characters after b in the return statement.