I'm trying to make a tool that gives you the average of a list of numbers. I'm using lists to keep track of the submitted numbers. The problem is that I can't figure out how to add the numbers on the list together. Does anyone know how to do that?
Offline
be back in a second!
http://scratch.mit.edu/projects/ssss/1603336
Will have a second One which is better soon!
Last edited by ssss (2011-02-18 01:16:58)
Offline
Here's a tutorial on it on the Scratch Wiki: Finding the Mean of Numbers
If you want to know how to find other averages (median, mode, range) then see this Scratch Wiki page: Finding the Average of Numbers (disambiguation)

Offline
Wystan wrote:
Make use of foreach loop. May be it will be beneficial for you.
There's no for each in scratch.
One of it's annoying parts. You can't say for each item in <list> do something with current.
Offline
juststickman wrote:
There's no for each in scratch.
One of it's annoying parts. You can't say for each item in <list> do something with current.
I made that block for my mod. Unfortunately I did something with the System Browser which means I can't access the source of it any more.
Offline
Set i to 1
Set average to 0
Repeat (length of numbers)
Change average by (item i of numbers)
Change i by 1
Set average to (average / length of numbers)This is how you do average:
Add the numbers, then divide by how many numbers there are
Offline
I know that. But I didn't know how to add the numbers in the list together unless I have a partiacular amount of numbers.
Offline
martianshark wrote:
I know that. But I didn't know how to add the numbers in the list together unless I have a partiacular amount of numbers.
I showed the script in my previous post.
This is how you make a 'for each' loop:
set i to 1
repeat (length of list)
*do whatever (the current item in the list is found with (item i of list))*
change i by 1Basically, you have an index variable ('i') which shows where you're at in the list, and you increment it at the end of the loop to get the next item.
Last edited by floppy_gunk (2011-02-21 03:15:23)
Offline
juststickman wrote:
Wystan wrote:
Make use of foreach loop. May be it will be beneficial for you.
There's no for each in scratch.
One of it's annoying parts. You can't say for each item in <list> do something with current.
Wouldn't it just be a:
[Repeat (length of list)]
<Do something>
[end repeat]
?
Offline
To find the average of a list.
] set [i v] to (1) repeat (length of [list v]) set [total v] to <(total) + (item (i) of [list v])> change [i v] by (1) end set [average v] to ((total) / (length of [list v]) )
Last edited by trinary (2012-03-11 20:01:46)
Offline