0
0
PowerShellscripting~20 mins

Integer and floating-point types in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell Number 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 code?
Consider the following PowerShell script:
$a = 5
$b = 2.5
$c = $a + $b
Write-Output $c.GetType().Name
What will be printed?
PowerShell
$a = 5
$b = 2.5
$c = $a + $b
Write-Output $c.GetType().Name
AString
BInt32
CDecimal
DDouble
Attempts:
2 left
💡 Hint
Adding an integer and a floating-point number results in a floating-point type.
🧠 Conceptual
intermediate
2:00remaining
Which type does PowerShell assign to the number 3.0 by default?
In PowerShell, if you assign the value 3.0 to a variable like this:
$x = 3.0
What is the default type of $x?
ADouble
BInt32
CSingle
DDecimal
Attempts:
2 left
💡 Hint
Numbers with decimal points default to a floating-point type.
📝 Syntax
advanced
2:00remaining
Which PowerShell assignment causes a type conversion error?
Which of the following assignments will cause a runtime error in PowerShell due to type mismatch?
A$z = [double] 5
B$x = [int] 3.7
C$y = [int] 'abc'
D$w = [float] 2.5
Attempts:
2 left
💡 Hint
Converting a non-numeric string to int causes an error.
🚀 Application
advanced
2:00remaining
How many items are in the resulting array after this PowerShell script?
What is the length of the array $arr after running this script?
$arr = @()
for ($i = 0; $i -lt 5; $i++) {
if ($i -is [int]) { $arr += $i }
else { $arr += [math]::Round($i) }
}
A5
B10
C0
D1
Attempts:
2 left
💡 Hint
The loop runs 5 times and adds one item each time.
🔧 Debug
expert
2:00remaining
What error does this PowerShell code raise?
Examine this code snippet:
$num = 1.5
$intNum = [int]$num
$result = $intNum / 0

What error will occur when running this code?
ANullReferenceException
BDivideByZeroException
CNo error, outputs Infinity
DInvalidCastException
Attempts:
2 left
💡 Hint
Dividing by zero causes an error in integer division.