0
0
Goprogramming~20 mins

Writing first Go program - Practice Problems & Coding Challenges

Choose your learning style9 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.