averages.poqs(文件已创建)
@@ -0,0 +1,35 @@ | |||
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"} : |
上一页
下一页