Which of the following is the main reason Go uses packages?
Think about how grouping code helps in big projects.
Packages help organize code into reusable parts, making it easier to manage and maintain.
What will be the output of this Go program?
package main import ( "fmt" "math" ) func main() { fmt.Println(math.Sqrt(16)) }
Look at what math.Sqrt does.
The math package provides the Sqrt function which returns the square root of a number. sqrt(16) = 4.
What error will this Go code produce?
package main func main() { println("Hello, world!") fmt.Println("Hello again!") }
Check if the fmt package is imported.
The code uses fmt.Println but does not import the fmt package, causing a compile error.
Which of these is NOT a benefit of using packages in Go?
Think about what packages do and do not do.
Packages help organize and reuse code but do not automatically make programs run faster.
You want to create a package named greetings with a function Hello that returns "Hello, Go!". Which code snippet correctly defines and uses this package?
Remember packages need to be imported and functions called with package name.
Option B correctly defines the greetings package with Hello function and imports it in main.go to call greetings.Hello().