Menu
CoddyTech

Recap - Number Stats

Part of the PowerShell Basics section of Coddy's PowerShell journey. Lesson 20 of 28.

challenge icon

Challenge

Easy

Read a line of whole numbers and print statistics about them, using a loop.

  1. Read a line with the prompt Numbers; the numbers are separated by single spaces. Turn each one into an [int].
  2. Print Count: , Sum: , Min: and Max: with the right values, one per line.
  3. 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.67

Try it yourself

$line = Read-Host "Numbers"
# Print the count, sum, min, max and average

All lessons in PowerShell Basics