Recap - Number Stats
Part of the PowerShell Basics section of Coddy's PowerShell journey. Lesson 20 of 28.
Challenge
EasyRead a line of whole numbers and print statistics about them, using a loop.
- Read a line with the prompt
Numbers; the numbers are separated by single spaces. Turn each one into an[int]. - Print
Count:,Sum:,Min:andMax:with the right values, one per line. - Print
Average:and the average with 2 decimals.
Find the minimum and the maximum with a foreach loop. The numbers can be negative.
With the input 9 -3 5, your script prints:
Numbers: 9 -3 5
Count: 3
Sum: 11
Min: -3
Max: 9
Average: 3.67Try it yourself
$line = Read-Host "Numbers"
# Print the count, sum, min, max and average
All lessons in PowerShell Basics
5Project: Password Checker
Project OverviewLength Check