averages.poqs
· 878 B · Text
Originalformat
Playground
We've collected the following data points --
- {data point of #4}
- {data point of #1}
- {data point of #7}
- {data point of #8}
- {data point of #1}
Let's find the average of these values. We've got a tally running, we
should continue accumulating values --
: {there are $count data points}
{data point of $x} {sum is $n}
>
{@add $count and #1 into &"there are * data points"}
{@add $n and $x into &"sum is *"} :
: {data point of $x}
>
{there are #1 data points}
{sum is $x} :
When we are out of data points to tabulate, we can finally compute the
average --
: {there are $count data points} {sum is $sum}
>
{@divide $sum by $count into &"the average is *"} :
Write out the finaly result to the console --
: {the average is $average}
>
{@write "The average is "}
{@write $average}
{@write ".\n"} :
| 1 | We've collected the following data points -- |
| 2 | - {data point of #4} |
| 3 | - {data point of #1} |
| 4 | - {data point of #7} |
| 5 | - {data point of #8} |
| 6 | - {data point of #1} |
| 7 | |
| 8 | Let's find the average of these values. We've got a tally running, we |
| 9 | should continue accumulating values -- |
| 10 | |
| 11 | : {there are $count data points} |
| 12 | {data point of $x} {sum is $n} |
| 13 | > |
| 14 | {@add $count and #1 into &"there are * data points"} |
| 15 | {@add $n and $x into &"sum is *"} : |
| 16 | |
| 17 | : {data point of $x} |
| 18 | > |
| 19 | {there are #1 data points} |
| 20 | {sum is $x} : |
| 21 | |
| 22 | When we are out of data points to tabulate, we can finally compute the |
| 23 | average -- |
| 24 | |
| 25 | : {there are $count data points} {sum is $sum} |
| 26 | > |
| 27 | {@divide $sum by $count into &"the average is *"} : |
| 28 | |
| 29 | Write out the finaly result to the console -- |
| 30 | |
| 31 | : {the average is $average} |
| 32 | > |
| 33 | {@write "The average is "} |
| 34 | {@write $average} |
| 35 | {@write ".\n"} : |
| 36 |