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
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...
Offline
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
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.
Offline
@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
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.
Offline
Should I make a basic one? That just has a list of numbers and outputs the average?
Offline
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
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.
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:
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) endI hope this helps, and also that you can understand whats happening here
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)
Offline
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
Offline
Thanks for your help prestige! I never had a counter! That's why I couldn't figure it out.
Offline
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
Offline
Isn't your min and max values wrong?
Offline
The values are meant to be bigger than the biggest value and smaller than the smallest value.
Offline
I mean, is max=-100000000 and min=1000000 correct?
Offline
Try it yourself, it should be
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)
Offline
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
Min/max values are an easy fix, counter is something you won't be familiar with unless you work a lot with lists.
Offline
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