Bird
Raised Fist0
Goprogramming~20 mins

Writing first Go program - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Go Beginner Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
Output of a simple Go program
What is the output of this Go program?
Go
package main
import "fmt"
func main() {
    fmt.Println("Hello, Go!")
}
AHello Go!
Bhello, go!
Chello Go
DHello, Go!
Attempts:
2 left
๐Ÿ’ก Hint
Look carefully at the exact string inside fmt.Println.
๐Ÿง  Conceptual
intermediate
1:30remaining
Purpose of the main function in Go
What is the role of the main function in a Go program?
AIt imports packages needed by the program.
BIt defines global variables for the program.
CIt is the starting point where the program begins execution.
DIt handles errors during program execution.
Attempts:
2 left
๐Ÿ’ก Hint
Think about where the computer starts running your code.
๐Ÿ”ง Debug
advanced
2:30remaining
Identify the error in this Go program
What error will this Go program produce when run?
Go
package main
import "fmt"
func main() {
    fmt.Println("Welcome to Go")
    fmt.Println("Let's learn")
    fmt.Println("Go is fun")
}
ARuntime error: index out of range
BSyntax error: missing closing parenthesis
CCompilation error: undefined function
DNo error, program runs fine
Attempts:
2 left
๐Ÿ’ก Hint
Check the parentheses in the last fmt.Println line.
๐Ÿ“ Syntax
advanced
2:00remaining
Correct way to import and use fmt package
Which option shows the correct way to import the fmt package and print "Go Rocks"?
A
import "fmt"
func main() { fmt.Println("Go Rocks") }
B
import fmt
func main() { fmt.Println("Go Rocks") }
C
import (fmt)
func main() { fmt.Println("Go Rocks") }
D
import fmt;
func main() { fmt.Println("Go Rocks") }
Attempts:
2 left
๐Ÿ’ก Hint
Remember how Go imports packages with quotes.
๐Ÿš€ Application
expert
2:30remaining
Output of a Go program with variable and fmt.Printf
What is the output of this Go program?
Go
package main
import "fmt"
func main() {
    name := "Go Learner"
    age := 3
    fmt.Printf("%s is %d years old.\n", name, age)
}
AGo Learner is 3 years old.
BGo Learner 3 years old.
C%s is %d years old.
DGo Learner is years old 3.
Attempts:
2 left
๐Ÿ’ก Hint
Look at how fmt.Printf formats strings with %s and %d.

Practice

(1/5)
1. What is the purpose of the main function in a Go program?
easy
A. It is the starting point where the program begins execution.
B. It defines a package for the program.
C. It imports external libraries.
D. It declares variables for the program.

Solution

  1. Step 1: Understand the role of main function

    The main function is special in Go; it is where the program starts running.
  2. Step 2: Differentiate from other parts

    Packages define code grouping, imports bring libraries, and variables store data, but none start execution.
  3. Final Answer:

    It is the starting point where the program begins execution. -> Option A
  4. Quick Check:

    Program starts at main() -> D [OK]
Hint: Remember: main() is the program's entry point [OK]
Common Mistakes:
  • Confusing package declaration with program start
  • Thinking imports start the program
  • Assuming variables control program flow
2. Which of the following is the correct way to print "Hello, Go!" in a Go program?
easy
A. fmt.Println("Hello, Go!")
B. print("Hello, Go!")
C. fmt.print("Hello, Go!")
D. console.log("Hello, Go!")

Solution

  1. Step 1: Identify the correct print function in Go

    Go uses the fmt package with Println to print with a newline.
  2. Step 2: Check syntax correctness

    fmt.Println("Hello, Go!") is correct; others are either wrong function names or from other languages.
  3. Final Answer:

    fmt.Println("Hello, Go!") -> Option A
  4. Quick Check:

    Use fmt.Println() to print lines in Go [OK]
Hint: Use fmt.Println() for printing with newline [OK]
Common Mistakes:
  • Using fmt.print instead of fmt.Println
  • Using print() which is not standard in Go
  • Using console.log from JavaScript
3. What will be the output of this Go program?
package main
import "fmt"
func main() {
    fmt.Println("Welcome to Go!")
}
medium
A. package main import "fmt" func main() { fmt.Println("Welcome to Go!") }
B. fmt.Println("Welcome to Go!")
C. Welcome to Go!
D. Error: missing main function

Solution

  1. Step 1: Understand program structure

    The program imports fmt and defines main(), which prints the string.
  2. Step 2: Identify output of fmt.Println

    It prints the string exactly: Welcome to Go! with a newline.
  3. Final Answer:

    Welcome to Go! -> Option C
  4. Quick Check:

    fmt.Println prints string output [OK]
Hint: fmt.Println prints the string content, not code [OK]
Common Mistakes:
  • Confusing code with output
  • Expecting code to print itself
  • Thinking main function is missing
4. Identify the error in this Go program:
package main
import "fmt"
func main() {
    fmt.Println("Hello, world!"
}
medium
A. Missing import statement
B. Incorrect function name
C. Missing package declaration
D. Missing closing parenthesis in fmt.Println call

Solution

  1. Step 1: Check syntax of fmt.Println

    The call to fmt.Println is missing a closing parenthesis at the end.
  2. Step 2: Verify other parts

    Package and import are present, function name is correct, so no errors there.
  3. Final Answer:

    Missing closing parenthesis in fmt.Println call -> Option D
  4. Quick Check:

    Check parentheses in function calls [OK]
Hint: Count opening and closing parentheses carefully [OK]
Common Mistakes:
  • Forgetting closing parenthesis in function calls
  • Assuming missing import or package causes this error
  • Misnaming main function
5. You want to write a Go program that prints "Hello" on one line and "World" on the next line. Which code snippet achieves this correctly?
hard
A. package main import "fmt" func main() { fmt.Print("Hello\nWorld") }
B. package main import "fmt" func main() { fmt.Println("Hello") fmt.Println("World") }
C. package main import "fmt" func main() { fmt.Println("Hello\nWorld") }
D. package main import "fmt" func main() { fmt.Print("Hello") fmt.Print("World") }

Solution

  1. Step 1: Understand printing with new lines

    fmt.Println prints text and adds a newline automatically.
  2. Step 2: Check each option's output

    A: Two fmt.Println calls print "Hello" on one line and "World" on the next. Correct.
    B: fmt.Print("Hello\nWorld") prints "Hello\nWorld" (with actual newline) on one line.
    C: fmt.Println("Hello\nWorld") prints "Hello\nWorld" (with actual newline) followed by newline, so output is two lines.
    D: Two fmt.Print calls print "HelloWorld" on one line.
  3. Final Answer:

    package main import "fmt" func main() { fmt.Println("Hello") fmt.Println("World") } -> Option B
  4. Quick Check:

    Use fmt.Println twice for separate lines [OK]
Hint: Use fmt.Println for each line to print separately [OK]
Common Mistakes:
  • Using fmt.Print without newline causes joined output
  • Expecting \n inside fmt.Println to create new line
  • Confusing fmt.Print and fmt.Println behavior
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard