Bird
Raised Fist0
Goprogramming~10 mins

Why operators are needed in Go - Test Your Understanding

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add two numbers and print the result.

Go
package main
import "fmt"
func main() {
    sum := 5 [1] 3
    fmt.Println(sum)
}
Drag options to blanks, or click blank then click option'
A*
B-
C/
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
2fill in blank
medium

Complete the code to check if a number is greater than 10.

Go
package main
import "fmt"
func main() {
    num := 15
    if num [1] 10 {
        fmt.Println("Number is greater than 10")
    }
}
Drag options to blanks, or click blank then click option'
A>
B==
C<
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than or equal instead of greater than.
3fill in blank
hard

Fix the error in the code to multiply two numbers correctly.

Go
package main
import "fmt"
func main() {
    a := 4
    b := 5
    product := a [1] b
    fmt.Println(product)
}
Drag options to blanks, or click blank then click option'
A*
B-
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or division instead of multiplication.
4fill in blank
hard

Fill both blanks to create a map of words and their lengths, including only words longer than 3 letters.

Go
package main
import "fmt"
func main() {
    words := []string{"go", "code", "fun", "learn"}
    lengths := map[string]int{
        [1]: len([2]),
    }
    fmt.Println(lengths)
}
Drag options to blanks, or click blank then click option'
A"code"
B"go"
Cwords[1]
Dwords[0]
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong index or mismatching key and value.
5fill in blank
hard

Fill all three blanks to create a map of words and their lengths, filtering words longer than 2 letters.

Go
package main
import "fmt"
func main() {
    words := []string{"go", "code", "fun", "learn"}
    lengths := map[string]int{}
    for _, word := range words {
        if len(word) [3] 2 {
            lengths[[1]] = [2]
        }
    }
    fmt.Println(lengths)
}
Drag options to blanks, or click blank then click option'
A"CODE"
Blen(word)
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators or mismatching key and value.

Practice

(1/5)
1. Why do we need operators in Go programming?
Operators help us to:
easy
A. Perform calculations and compare values
B. Write comments in the code
C. Create new data types
D. Store data permanently on disk

Solution

  1. Step 1: Understand the role of operators

    Operators are symbols that let us do math like addition or compare values like equal or greater than.
  2. Step 2: Identify what operators do in code

    They help perform calculations and make decisions by comparing values, which is essential for programming logic.
  3. Final Answer:

    Perform calculations and compare values -> Option A
  4. Quick Check:

    Operators = calculations and comparisons [OK]
Hint: Operators do math and comparisons in code [OK]
Common Mistakes:
  • Thinking operators create data types
  • Confusing operators with comments
  • Believing operators store data on disk
2. Which of the following is the correct way to use the addition operator in Go?
var sum = 5 ? 3
easy
A. +
B. -
C. *
D. /

Solution

  1. Step 1: Identify the addition operator symbol

    In Go, the plus sign + is used to add two numbers.
  2. Step 2: Apply the operator to the expression

    Using 5 + 3 correctly adds the two numbers to get 8.
  3. Final Answer:

    + -> Option A
  4. Quick Check:

    Addition operator = + [OK]
Hint: Use + for addition in Go [OK]
Common Mistakes:
  • Using - instead of + for addition
  • Confusing * (multiplication) with +
  • Using / which is division
3. What will be the output of this Go code?
package main
import "fmt"
func main() {
  a := 10
  b := 3
  fmt.Println(a % b)
}
medium
A. 3
B. 1
C. 0
D. Syntax error

Solution

  1. Step 1: Understand the modulus operator %

    The % operator gives the remainder of division. Here, 10 divided by 3 leaves a remainder of 1.
  2. Step 2: Calculate the remainder

    10 ÷ 3 = 3 with remainder 1, so a % b is 1.
  3. Final Answer:

    1 -> Option B
  4. Quick Check:

    10 % 3 = 1 [OK]
Hint: Modulus % gives remainder after division [OK]
Common Mistakes:
  • Confusing % with division /
  • Expecting 0 instead of remainder
  • Thinking % causes syntax error
4. Find the error in this Go code snippet:
package main
import "fmt"
func main() {
  x := 5
  y := 10
  if x = y {
    fmt.Println("Equal")
  }
}
medium
A. Variables x and y are not declared
B. Missing semicolon after variable declaration
C. Using assignment '=' instead of comparison '==' in if condition
D. Incorrect print function name

Solution

  1. Step 1: Check the if condition syntax

    The condition uses = which assigns y to x instead of comparing them.
  2. Step 2: Correct the comparison operator

    Use == to compare values in Go if statements.
  3. Final Answer:

    Using assignment '=' instead of comparison '==' in if condition -> Option C
  4. Quick Check:

    Comparison needs ==, not = [OK]
Hint: Use == for comparison, = is assignment [OK]
Common Mistakes:
  • Using = instead of == in conditions
  • Thinking semicolons are mandatory after declarations
  • Confusing println with print
5. You want to check if a number is between 10 and 20 (inclusive) in Go. Which operator combination correctly does this?
if x ? 10 && x ? 20 {
  println("In range")
}
hard
A. <= and >=
B. > and <
C. == and !=
D. >= and <=

Solution

  1. Step 1: Understand the range condition

    To check if x is between 10 and 20 inclusive, x must be greater than or equal to 10 and less than or equal to 20.
  2. Step 2: Match operators to condition

    Use >= for "greater or equal" and <= for "less or equal" to include boundaries.
  3. Final Answer:

    >= and <= -> Option D
  4. Quick Check:

    Inclusive range uses >= and <= [OK]
Hint: Use >= and <= for inclusive range checks [OK]
Common Mistakes:
  • Using > and < excludes boundary values
  • Swapping operators in wrong order
  • Using == and != which don't check ranges
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