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

#1 2013-03-11 23:12:11

destineegurl22
New Scratcher
Registered: 2013-03-10
Posts: 1

Need help with list

I just installed class for my computer science class and i'm having a little trouble on the lists. I can print all my outputs on a list but i don't know how to add everything on that list.
For example, my project right now is to be able to add a number of test grades and then average them to the numerical value.
i have no problem inputing all the test grades into a list but i don't know how to set it up so that all the numbers i inputed into that list will be added altogether.

Offline

 

#2 2013-03-12 02:19:50

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: Need help with list

I don't have the blocks right now, but what you should do is use a variable as a counter, and another as the sum. Take the "counter"th number (start at 1, so first) and add that and the current sum (0 when start) and set it to the sum. Then change counter by 1 (to 2) and add the counterth (2nd) term to the sum. Put that in a repeat for X times, where X is the length of the list.

Offline

 

#3 2013-03-12 03:27:32

jji7skyline
Scratcher
Registered: 2010-03-08
Posts: 1000+

Re: Need help with list

when gf clicked
set [counter v] to (1)
repeat (length of [list v]
 change [grade v] by (item (counter) of [list v])
 change [counter v] by (1)
end
You might have to adjust the script depending on how your grades are counted, but this is the basic script for adding all the numbers in list together. The total is stored in the grade variable.

Last edited by jji7skyline (2013-03-12 03:27:58)


I don't know why you say goodbye, I say hello!  big_smile

Offline

 

Board footer