Bird
Raised Fist0
Goprogramming~20 mins

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

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

Practice

(1/5)
1. What does fmt.Print do in Go programming?
easy
A. It automatically adds a new line after printing.
B. It formats text with colors and styles.
C. It only prints variables, not text.
D. It prints text or values exactly as given without adding spaces or new lines.

Solution

  1. Step 1: Understand fmt.Print behavior

    fmt.Print prints exactly what you give it without adding spaces or new lines automatically.
  2. Step 2: Compare with other fmt functions

    Unlike fmt.Println, it does not add a new line after printing.
  3. Final Answer:

    It prints text or values exactly as given without adding spaces or new lines. -> Option D
  4. Quick Check:

    fmt.Print prints exactly as given [OK]
Hint: Remember: fmt.Print prints exactly, no extra spaces or new lines [OK]
Common Mistakes:
  • Thinking fmt.Print adds a new line automatically
  • Confusing fmt.Print with fmt.Println
  • Assuming fmt.Print formats text with colors
2. Which of the following is the correct syntax to print two values using fmt.Print in Go?
easy
A. fmt.Print("Hello", "World")
B. fmt.Print("Hello" + "World")
C. fmt.Print("Hello" "World")
D. fmt.Print("Hello" & "World")

Solution

  1. Step 1: Check how to print multiple values

    In Go, fmt.Print accepts multiple arguments separated by commas to print them together.
  2. Step 2: Analyze each option

    fmt.Print("Hello", "World") uses commas correctly. fmt.Print("Hello" + "World") tries to add strings with + which is valid but prints concatenated string as one argument. fmt.Print("Hello" "World") is invalid syntax. fmt.Print("Hello" & "World") uses & which is invalid for strings.
  3. Final Answer:

    fmt.Print("Hello", "World") -> Option A
  4. Quick Check:

    Use commas to print multiple values [OK]
Hint: Use commas to separate values inside fmt.Print [OK]
Common Mistakes:
  • Using + to join strings inside fmt.Print
  • Omitting commas between values
  • Using invalid operators like & between strings
3. What is the output of this Go code?
package main
import "fmt"
func main() {
    fmt.Print("Go", 1, 2)
}
medium
A. Go12
B. Go 1 2
C. Go 12
D. Go,1,2

Solution

  1. Step 1: Understand fmt.Print output format

    fmt.Print prints values exactly as given without spaces or new lines unless explicitly added.
  2. Step 2: Analyze the arguments

    Arguments are "Go", 1, and 2. They print one after another without spaces, so output is "Go12".
  3. Final Answer:

    Go12 -> Option A
  4. Quick Check:

    fmt.Print joins values without spaces [OK]
Hint: fmt.Print prints values side by side without spaces [OK]
Common Mistakes:
  • Assuming spaces are added automatically
  • Expecting commas or other separators
  • Confusing fmt.Print with fmt.Println
4. Find the error in this Go code snippet:
package main
import "fmt"
func main() {
    fmt.Print("Hello" "World")
}
medium
A. Missing import statement
B. Missing comma between string arguments
C. fmt.Print cannot print strings
D. Missing parentheses in fmt.Print

Solution

  1. Step 1: Check syntax of fmt.Print arguments

    Multiple arguments must be separated by commas in Go function calls.
  2. Step 2: Identify the error

    Strings "Hello" and "World" are written without a comma, causing syntax error.
  3. Final Answer:

    Missing comma between string arguments -> Option B
  4. Quick Check:

    Separate multiple arguments with commas [OK]
Hint: Always separate multiple arguments with commas [OK]
Common Mistakes:
  • Omitting commas between arguments
  • Thinking fmt.Print can't print strings
  • Forgetting import "fmt"
5. You want to print the numbers 1, 2, and 3 on the same line with spaces between them using fmt.Print. Which code snippet achieves this?
hard
A. fmt.Print("1 2 3")
B. fmt.Print(1 + 2 + 3)
C. fmt.Print(1, " ", 2, " ", 3)
D. fmt.Print(1, 2, 3)

Solution

  1. Step 1: Understand fmt.Print behavior with multiple arguments

    It prints all arguments exactly as given without adding spaces automatically.
  2. Step 2: Add spaces explicitly

    To print spaces between numbers, include space strings " " as separate arguments.
  3. Step 3: Analyze options

    fmt.Print(1, " ", 2, " ", 3) prints 1, space, 2, space, 3 correctly. fmt.Print(1 + 2 + 3) sums numbers and prints 6. fmt.Print("1 2 3") prints a string but not numbers as values. fmt.Print(1, 2, 3) prints numbers without spaces.
  4. Final Answer:

    fmt.Print(1, " ", 2, " ", 3) -> Option C
  5. Quick Check:

    Add spaces as separate arguments in fmt.Print [OK]
Hint: Add spaces as separate string arguments to fmt.Print [OK]
Common Mistakes:
  • Expecting fmt.Print to add spaces automatically
  • Using + to join numbers instead of printing separately
  • Printing numbers as a single string without variables
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