Split the work into four functions: clear the table, fill it with random numbers, add them up and print the average.

This tutorial is part of the Nairda learning path. You can build it step by step inside the app, which checks every block you place before letting you move on.


The steps

  1. We create a table called data.
  2. We create two number variables, index and result.
  3. We create a text variable called terminal.
  4. We create the four functions: clear, fill, compute and print.
  5. And the other two functions, compute and print.
  6. In the clear canvas we empty the terminal.
  7. Behind it we add a Repeat.
  8. It runs as many times as the table is wide.
  9. Inside the Repeat we remove one column, so the table ends up empty.
  10. In the fill canvas we set index back to 0.
  11. Behind it a Repeat of 10 turns, one per number.
  12. Inside it we write a random number into the table.
  13. The random number goes from 0 to 100.
  14. The column it writes into is the variable index.
  15. Behind it we add a Set with an operation inside.
  16. The operation adds one to index, to move to the next column.
  17. And we add a new column, so there is room for the next one.
  18. In the compute canvas we set index back to 0.
  19. Behind it a Repeat of 10 turns, one per number.
  20. Inside it we add a Set with an operation inside.
  21. What it sums is result itself, so the numbers pile up.
  22. What it adds is what the table holds at the column index.
  23. Behind it we add another Set with an operation inside.
  24. That one adds one to index, to move to the next column.
  25. After the Repeat we add one more Set, with an operation inside.
  26. We change that operation to a division.
  27. It divides result by 10, which is the average of the ten numbers.
  28. In the print canvas we set index back to 0.
  29. Behind it another Repeat of 10 turns.
  30. Inside it we add a Join, which writes into the terminal.
  31. What it writes is what the table holds.
  32. And the column it reads is the variable index.
  33. Behind it we add a Set with an operation inside.
  34. The operation adds one to index, to move to the next column.
  35. After the Repeat we write the word result.
  36. And behind it the value of result.
  37. Back in the main canvas we add a While loop, which repeats forever.
  38. Above it we call fill, which loads the table.
  39. And above that, clear, so the table starts empty.
  40. And behind them we call compute and print.
  41. On the dashboard we draw a terminal.
  42. And we drag the variable terminal onto it.

When you finish, the app takes you straight to the next tutorial in the path.

Build it in Nairda