Bird
Raised Fist0
PowerShellscripting~20 mins

Arithmetic operators in PowerShell - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
PowerShell Arithmetic Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PowerShell arithmetic operation?
Consider the following PowerShell command:
$result = 5 + 3 * 2
$result

What is the output?
PowerShell
$result = 5 + 3 * 2
$result
A11
BError
C10
D16
Attempts:
2 left
💡 Hint
Remember the order of operations: multiplication happens before addition.
💻 Command Output
intermediate
2:00remaining
What is the output of this division and modulus operation?
Look at this PowerShell code:
$a = 17
$b = 4
$div = [math]::Floor($a / $b)
$mod = $a % $b
"Division: $div, Modulus: $mod"

What will be printed?
PowerShell
$a = 17
$b = 4
$div = [math]::Floor($a / $b)
$mod = $a % $b
"Division: $div, Modulus: $mod"
ADivision: 5, Modulus: 1
BDivision: 4.25, Modulus: 1
CDivision: 4, Modulus: 1
DDivision: 4, Modulus: 0
Attempts:
2 left
💡 Hint
Division result is floored to get integer division.
📝 Syntax
advanced
2:00remaining
Which option correctly increments a variable by 1 in PowerShell?
You want to increase the value of variable $count by 1. Which of these commands will do it correctly?
A++$count
B$count++
C$count += 1
D$count = $count + 1
Attempts:
2 left
💡 Hint
PowerShell does not support ++ or -- operators.
💻 Command Output
advanced
2:00remaining
What is the output of this PowerShell expression with mixed operators?
Evaluate this PowerShell expression:
$x = 10
$y = 3
$result = $x / $y * 2 - 1
$result

What is the output?
PowerShell
$x = 10
$y = 3
$result = $x / $y * 2 - 1
$result
A5.66666666666667
B5.66666666666666
C5.6666666666667
D5.66666666666668
Attempts:
2 left
💡 Hint
Division and multiplication have the same precedence and are evaluated left to right.
🔧 Debug
expert
2:00remaining
Why does this PowerShell script produce an error?
This script is intended to calculate the remainder of 15 divided by 4:
$a = 15
$b = 4
$remainder = $a mod $b
Write-Output $remainder

Why does it fail?
PowerShell
$a = 15
$b = 4
$remainder = $a mod $b
Write-Output $remainder
AVariables $a and $b are not initialized properly.
B'mod' is not a valid operator in PowerShell; use '%' instead.
CWrite-Output cannot output variables directly.
DPowerShell requires parentheses around arithmetic expressions.
Attempts:
2 left
💡 Hint
Check the operator used for modulus in PowerShell.

Practice

(1/5)
1. Which arithmetic operator in PowerShell is used to find the remainder of a division?
easy
A. The multiplication operator (*)
B. The division operator (/)
C. The modulus operator (%)
D. The subtraction operator (-)

Solution

  1. Step 1: Understand the modulus operator

    The modulus operator (%) returns the remainder after division of two numbers.
  2. Step 2: Compare with other operators

    Division (/) returns the quotient, multiplication (*) multiplies, subtraction (-) subtracts.
  3. Final Answer:

    The modulus operator (%) -> Option C
  4. Quick Check:

    Remainder = % operator [OK]
Hint: Remainder uses % operator in math [OK]
Common Mistakes:
  • Confusing division (/) with modulus (%)
  • Using * or - for remainder
  • Thinking % means percentage, not remainder
2. Which of the following is the correct syntax to multiply two numbers 5 and 3 in PowerShell?
easy
A. Write-Output 5 & 3
B. Write-Output 5 * 3
C. Write-Output 5 multiply 3
D. Write-Output 5 x 3

Solution

  1. Step 1: Identify the multiplication operator in PowerShell

    PowerShell uses * for multiplication between numbers.
  2. Step 2: Check syntax correctness

    Write-Output 5 * 3 correctly multiplies 5 and 3 and outputs the result.
  3. Final Answer:

    Write-Output 5 * 3 -> Option B
  4. Quick Check:

    Multiplication uses * operator [OK]
Hint: Use * for multiplication in PowerShell [OK]
Common Mistakes:
  • Using 'x' or 'multiply' instead of *
  • Using & which is a different operator
  • Missing spaces around operator causing errors
3. What will be the output of the following PowerShell code?
$a = 10
$b = 3
$c = $a / $b
Write-Output $c
medium
A. 3
B. 3.0
C. Error
D. 3.33333333333333

Solution

  1. Step 1: Understand division operator behavior

    In PowerShell, dividing integers returns a floating-point number with decimals.
  2. Step 2: Calculate 10 divided by 3

    10 / 3 equals approximately 3.33333333333333.
  3. Final Answer:

    3.33333333333333 -> Option D
  4. Quick Check:

    Division returns float result [OK]
Hint: Division returns decimal numbers, not just integers [OK]
Common Mistakes:
  • Expecting integer 3 instead of decimal
  • Thinking division causes error
  • Confusing with integer division truncation
4. Identify the error in this PowerShell script:
$x = 8
$y = 2
$z = $x % $y
Write-Output $z
medium
A. There is no error; script runs correctly
B. Variables must be declared with types before use
C. The modulus operator (%) is not valid in PowerShell
D. Write-Output cannot print variables

Solution

  1. Step 1: Check validity of modulus operator

    PowerShell supports % as the modulus operator to get remainder.
  2. Step 2: Verify variable usage and output

    Variables can be assigned without explicit types, and Write-Output prints values correctly.
  3. Final Answer:

    There is no error; script runs correctly -> Option A
  4. Quick Check:

    Modulus and Write-Output are valid [OK]
Hint: Modulus (%) works fine; no type declaration needed [OK]
Common Mistakes:
  • Thinking % is invalid operator
  • Believing variables need explicit types
  • Assuming Write-Output can't print variables
5. You want to calculate the average of three numbers 4, 7, and 9 in PowerShell. Which script correctly does this using arithmetic operators?
hard
A. $avg = (4 + 7 + 9) / 3; Write-Output $avg
B. $avg = 4 + 7 + 9 / 3; Write-Output $avg
C. $avg = 4 + 7 + 9 % 3; Write-Output $avg
D. $avg = (4 * 7 * 9) / 3; Write-Output $avg

Solution

  1. Step 1: Understand average calculation formula

    Average = sum of numbers divided by count, so (4 + 7 + 9) / 3.
  2. Step 2: Check each option's calculation

    $avg = (4 + 7 + 9) / 3; Write-Output $avg correctly sums all three then divides by 3. $avg = 4 + 7 + 9 / 3; Write-Output $avg divides 9 by 3 first, then adds 4 and 7, wrong order. $avg = 4 + 7 + 9 % 3; Write-Output $avg uses modulus incorrectly. $avg = (4 * 7 * 9) / 3; Write-Output $avg multiplies numbers, not sum.
  3. Final Answer:

    $avg = (4 + 7 + 9) / 3; Write-Output $avg -> Option A
  4. Quick Check:

    Average = sum / count [OK]
Hint: Use parentheses to sum before dividing for average [OK]
Common Mistakes:
  • Missing parentheses causing wrong order
  • Using modulus (%) instead of division
  • Multiplying numbers instead of summing
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