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

#1 2012-07-25 14:06:10

Apocolipto
New Scratcher
Registered: 2012-07-25
Posts: 9

Hey guys,first post.Urgent help needed?

Hi, I'm new to the forums, and would like some urgent help as I can't figure it out.

I need to write this for a school homework,but been struggling the whole day and haven't figured anything out.The scripting would be nice for those prepared to write it, and I believe it's not much.

Program to write:"A scientist receives a number of values as result of a experiment that was conducted.A program is needed  to read these values and determine the highest,lowest and average values.It also has to display which values are higher than average.

-Create a scratch program and make a list (Values.) I have done this.
-Enter values into list.(Done)
-Write code to do the necessary calculations."

Anybody please help?!

Offline

 

#2 2012-07-25 14:08:11

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: Hey guys,first post.Urgent help needed?

Well, first, I'm assuming you know what the average means.  I think I may have a script that finds the highest and lowest amounts, but I don't generally work with lists...


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#3 2012-07-25 14:15:12

Apocolipto
New Scratcher
Registered: 2012-07-25
Posts: 9

Re: Hey guys,first post.Urgent help needed?

Maybe your script can help? Please. And I understand the theory behind how to work the average, but not how to go about it using a list.Any help?

Offline

 

#4 2012-07-25 14:15:52

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Hey guys,first post.Urgent help needed?

As it is an assignment, I'm hesitant to hand out the code, but here are your basic steps.

1) loop through the list and find the sum
2) divide by the length of the list (average = (sum)/(length of [list v])
3) loop through the list and find the highest variable (requires one variable)
4) loop through the list and find the lowest variable (requires one variable)
5) loop through the list and add any number greater than "average" to a second list

If you solve it, you could try solving it with only two loops.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#5 2012-07-25 14:29:16

Apocolipto
New Scratcher
Registered: 2012-07-25
Posts: 9

Re: Hey guys,first post.Urgent help needed?

@Moregamesnow,Thanks for that.But I still can't find out how to practicly go about it.It's not for marks guys, but I want to show that I could do it.And at the moment I'm dissapointed.Practicly I can't.Please help me with coding.From there I'll "decypher" and see what I should have done.

Offline

 

#6 2012-07-25 14:32:29

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: Hey guys,first post.Urgent help needed?

Im not going to dish out the code, but ill tell you the basic function.

You need to find the average first. Then you sort through the list one by one and determine which ones are above the average.


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#7 2012-07-25 14:32:51

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: Hey guys,first post.Urgent help needed?

Should I make a basic one?  That just has a list of numbers and outputs the average?


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#8 2012-07-25 14:40:32

Apocolipto
New Scratcher
Registered: 2012-07-25
Posts: 9

Re: Hey guys,first post.Urgent help needed?

Yes please! Someone understands that I can't do it,and maybe a rough example of how to use the loop to find the highest number.At the moment I'm "hand-picking" the values and adding them together to get the average.Then I divide the sum by Length of list.That I understand. But I can't figure out how to do it with a loop!

Offline

 

#9 2012-07-25 15:07:56

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: Hey guys,first post.Urgent help needed?

The most important bit of this isn't the code but the understanding. From what I see, you understand the theory and can do it by hand, which is why I'm happy to provide the code. I'm assuming this is a math assignment, or at least that you'll understand whats happening. If you have any questions on it then please ask, its better that you fully understand whats happening.

It seems your main problem is that you haven't included a 'counting' variable, which are very useful when using lists. Thats what the 'counter' variable in the script is for:

1) Make a variable called counter.
2) Add all the values to a list.
3) Make a variable called average

Now first, run this script to find the average.

set [counter v] to (1)
set [average v] to (0)
Repeat (Length of [list v])
set [average v] to ((average) + (item (counter) of [list v]))
change [counter v] by (1)
end
set [average v] to ((average) / (length of [list v]))
This will total up all the values and divide the total by the number of values, thus giving the average.

Now to work out maximum and minimum values:
1) make a variable called minimum
2) make a variable called maximum
set [counter v] to (1)
set [minimum v] to (100000000000000000)
set [maximum v] to (-100000000000000000)
repeat (Length of [list v])
if <(item (counter) of [list v]) < (minimum)>
set [minimum v] to (item (counter) of [list v])
end
if <(item (counter) of [list v]) > (maximum)>
set [maximum v] to (item (counter) of [list v])
end
change [counter v] by (1)
Finally, to find out the values that are greater than the average:
1) make a new list " >average "

set [counter v] to (1)
delete [all v] of [>average v]
repeat (length of [list v])
if <(item (counter) of [list v]) > (average)>
add (item (counter) of [list v]) to [>average v]
end
change [counter v] by (1)
end
I hope this helps, and also that you can understand whats happening here  smile

So you can run 1 script to work it all out:

when gf clicked
set [counter v] to (1)
set [average v] to (0)
set [minimum v] to (100000000000000000)
set [maximum v] to (-100000000000000000)
Repeat (Length of [list v])
set [average v] to ((average) + (item (counter) of [list v]))
if <(item (counter) of [list v]) < (minimum)>
set [minimum v] to (item (counter) of [list v])
end
if <(item (counter) of [list v]) > (maximum)>
set [maximum v] to (item (counter) of [list v])
end
change [counter v] by (1)
end
set [average v] to ((average) / (length of [list v]))
set [counter v] to (1)
delete [all v] of [>average v]
repeat (length of [list v])
if <(item (counter) of [list v]) > (average)>
add (item (counter) of [list v]) to [>average v]
end
change [counter v] by (1)
end

Last edited by Prestige (2012-07-25 15:27:03)


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#10 2012-07-25 15:13:25

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: Hey guys,first post.Urgent help needed?

Wes64 wrote:

Im not going to dish out the code, but ill tell you the basic function.

You need to find the average first. Then you sort through the list one by one and determine which ones are above the average.

Ah, I should have been the better man like Wes  hmm


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#11 2012-07-25 15:29:14

Apocolipto
New Scratcher
Registered: 2012-07-25
Posts: 9

Re: Hey guys,first post.Urgent help needed?

Thanks for your help prestige! I never had a counter! That's why I couldn't figure it out.

Offline

 

#12 2012-07-25 15:32:33

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: Hey guys,first post.Urgent help needed?

Apocolipto wrote:

Thanks for your help prestige! I never had a counter! That's why I couldn't figure it out.

I was hesitant to provide the full script given that it was school work - but you seemed to have all the foundations there and just missing one small thing. And its such a small script too. No problem  smile


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#13 2012-07-25 15:33:51

Apocolipto
New Scratcher
Registered: 2012-07-25
Posts: 9

Re: Hey guys,first post.Urgent help needed?

Isn't your min and max values wrong?

Offline

 

#14 2012-07-25 15:35:53

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: Hey guys,first post.Urgent help needed?

The values are meant to be bigger than the biggest value and smaller than the smallest value.


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#15 2012-07-25 15:38:43

Apocolipto
New Scratcher
Registered: 2012-07-25
Posts: 9

Re: Hey guys,first post.Urgent help needed?

I mean, is max=-100000000 and min=1000000 correct?

Offline

 

#16 2012-07-25 15:40:50

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: Hey guys,first post.Urgent help needed?

Try it yourself, it should be  smile

The max value has to be low so everything will be higher than it. Alternatively you could do the average and min/max scripts separately and set them both to the average instead of 1x10^8 or whatever.

Last edited by Prestige (2012-07-25 15:42:22)


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#17 2012-07-25 15:45:05

Apocolipto
New Scratcher
Registered: 2012-07-25
Posts: 9

Re: Hey guys,first post.Urgent help needed?

Ran it,and it worked. My problems, I set my max values in loop to 10000 and min to -10000.And didn't have a counter.

Offline

 

#18 2012-07-25 15:55:28

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: Hey guys,first post.Urgent help needed?

Min/max values are an easy fix, counter is something you won't be familiar with unless you work a lot with lists.


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#19 2012-07-27 14:25:02

Apocolipto
New Scratcher
Registered: 2012-07-25
Posts: 9

Re: Hey guys,first post.Urgent help needed?

I have another question folks.Been writing a program,and it's challenging me.I wrote a program where the sprite asks you to enter 10 words,and he adds it to the first list.Now,I loop the program,and add the words to the second list.What I want the program to do is reverse the words upon adding to the second list.Example: One,add to second list as enO. Any ideas?

Main reason for program is to get a feel for looping and using the counter.

Offline

 

Board footer