0
0
Goprogramming~20 mins

Output using fmt.Print in Go - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Go fmt.Print Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
What is the output of this Go code using fmt.Print?
Look at the code below. What will it print when run?
Go
package main
import "fmt"
func main() {
    fmt.Print("Hello")
    fmt.Print(" ")
    fmt.Print("World")
}
AHello\nWorld
BHello World\n
CHello World
DHelloWorld\n
Attempts:
2 left
๐Ÿ’ก Hint
fmt.Print prints exactly what you give it without adding new lines.
โ“ Predict Output
intermediate
2:00remaining
What does this Go code print with fmt.Print and fmt.Println?
Check the output of this program:
Go
package main
import "fmt"
func main() {
    fmt.Print("Go")
    fmt.Println("Lang")
    fmt.Print("!\n")
}
A
GoLang
B
!
gnaLoG
C
oLang
!
D
GoLang
!
Attempts:
2 left
๐Ÿ’ก Hint
fmt.Println adds a new line after printing, fmt.Print does not.
โ“ Predict Output
advanced
2:00remaining
What is the output of this Go code using fmt.Print with variables?
What will this program print?
Go
package main
import "fmt"
func main() {
    a := 5
    b := 10
    fmt.Print("Sum: ", a+b)
}
ASum: a+b
BSum: 15
CSum: 510
DSum: 5+10
Attempts:
2 left
๐Ÿ’ก Hint
The + operator adds numbers, not strings, when used with integers.
โ“ Predict Output
advanced
2:00remaining
What error does this Go code produce?
What happens when you run this code?
Go
package main
import "fmt"
func main() {
    fmt.Print("Number: " + 5)
}
Acompile error: invalid operation: mismatched types string and int
BNumber: 5\n
CNumber: 5
Druntime error
Attempts:
2 left
๐Ÿ’ก Hint
You cannot add a string and an int directly in Go.
๐Ÿง  Conceptual
expert
2:00remaining
How many characters are printed by this Go program using fmt.Print?
Count the total characters printed by this program:
Go
package main
import "fmt"
func main() {
    fmt.Print("Go")
    fmt.Print(" ")
    fmt.Print(123)
}
A6
B5
C7
D8
Attempts:
2 left
๐Ÿ’ก Hint
Remember numbers printed by fmt.Print are converted to their string form.