This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-02-18 01:09:03

martianshark
Scratcher
Registered: 2008-03-24
Posts: 1000+

Average Tool

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?


http://img.geocaching.com/stats/img.aspx?txt=martianshark&uid=e6cdc2c8-2476-4abd-9994-27f857396579&bg=1

Offline

 

#2 2011-02-18 01:12:39

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: Average Tool

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)


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#3 2011-02-18 04:44:24

Wystan
New Scratcher
Registered: 2011-02-09
Posts: 8

Re: Average Tool

Make use of foreach loop. May be it will be beneficial for you.

Offline

 

#4 2011-02-19 13:43:15

martianshark
Scratcher
Registered: 2008-03-24
Posts: 1000+

Re: Average Tool

That doesn't help me much. I want to be able to add any amount of numbers.


http://img.geocaching.com/stats/img.aspx?txt=martianshark&uid=e6cdc2c8-2476-4abd-9994-27f857396579&bg=1

Offline

 

#5 2011-02-19 14:03:26

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Average Tool


You can now reach me on Twitter @johnnydean1_

Offline

 

#6 2011-02-20 09:51:31

WeirdF
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Average Tool

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)


http://i.cr3ation.co.uk/dl/s1/gif/847032b8a331def77529b6a0384db1fe_handfingers.gif

Offline

 

#7 2011-02-20 10:00:45

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Average Tool

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.


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#8 2011-02-20 15:30:55

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: Average Tool

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.  sad


/* No comment */

Offline

 

#9 2011-02-20 23:26:35

floppy_gunk
Scratcher
Registered: 2008-11-14
Posts: 500+

Re: Average Tool

Code:

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


http://img163.imageshack.us/img163/1917/2856lg.jpg Get it now!  smile

Offline

 

#10 2011-02-21 00:39:24

martianshark
Scratcher
Registered: 2008-03-24
Posts: 1000+

Re: Average Tool

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.


http://img.geocaching.com/stats/img.aspx?txt=martianshark&amp;uid=e6cdc2c8-2476-4abd-9994-27f857396579&amp;bg=1

Offline

 

#11 2011-02-21 01:07:52

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: Average Tool

Check the lengh of the list?  hmm


Hai.

Offline

 

#12 2011-02-21 03:07:00

floppy_gunk
Scratcher
Registered: 2008-11-14
Posts: 500+

Re: Average Tool

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:

Code:

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 1

Basically, 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.

http://img189.imageshack.us/img189/1908/average.gif

Last edited by floppy_gunk (2011-02-21 03:15:23)


http://img163.imageshack.us/img163/1917/2856lg.jpg Get it now!  smile

Offline

 

#13 2011-02-22 05:08:26

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Average Tool

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]

?


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#14 2012-03-11 15:02:42

MeTwo
Scratcher
Registered: 2010-11-29
Posts: 14

Re: Average Tool

Check out my project called "Average 1s1s" download it and look at the scrips. Hope it helps!

Offline

 

#15 2012-03-11 20:00:42

trinary
Scratcher
Registered: 2012-01-29
Posts: 1000+

Re: Average Tool

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)


http://trinary.tk/images/signature_.php

Offline

 

Board footer