I really need help on The Hunt Begins.
# Senick is trying to find the elusive Burleous Majoris!
# But he doesn't know how big a Burleous Majoris would be...
# Find the average size of this burl population to use as a baseline!
# This function returns average size of all the burls in an array.
def averageSize(burls):
sum = sumSize(burls)
# Remember the average is the sum of the parts divided by the amount!
return sum / burls.length
# This function should return the sum of all the burls sizes.
def sumSize(burls):
# Implement the sum function using the burls 'size':
s = burls.sum
return s
while True:
# Find the average size of the burls by calling the 'averageSize' function.
q = averageSize(burls)
# Say the average size of the seen burls!
hero.say(q)
1 Like
It tells me burls is undefined
1 Like
burls is obviously undefined, but how do I make the hero only look at burls?
2 Likes
Are you trying to find a list of all the burls?
If so,
burls = hero.findByType("burl")
2 Likes
Thank you! Now it does not give me any errors, but the hero does the functions before the burls come out, and therefore says “0” to Senick.
Here is my updated code:
# Senick is trying to find the elusive Burleous Majoris!
# But he doesn't know how big a Burleous Majoris would be...
# Find the average size of this burl population to use as a baseline!
# This function returns average size of all the burls in an array.
def averageSize(burls):
sum = sumSize(burls)
# Remember the average is the sum of the parts divided by the amount!
return sum / burls.length
# This function should return the sum of all the burls sizes.
def sumSize(burls):
# Implement the sum function using the burls 'size':
sum = sum(burls.size)
return sum
while True:
# Find the average size of the burls by calling the 'averageSize' function.
burls = hero.findByType("burl")
q = averageSize(burls)
# Say the average size of the seen burls!
hero.say(q)
@_TD_RodYT, I cannot find a way to make my hero say the average size after the burls come by.
Do you know a way? And if so, could you tell me what it is?
1 Like
The instructions for this level are not really clear so I’ll make it more clear. When we pass burls
, we are passing a list of all the burls on the screen. You do not have to worry about your hero starting too early because you put the code inside a while loop.
Now, inside the sumSize function, you want to loop the code in a for loop.
- Define “sum” in sumSize. You can set it to 0. (Outside of the loop)
- Inside the for loop you want to keep on adding the burl’s size to sum:
for burl in burls
sum = sum + burl.size;
Now that you have to total size of all the burls combined, you will divide it by burls’ length in averageSize to find the average weight. I usually don’t give away free code like this but the goal of the level was unclearly stated in the Hints.
2 Likes
You want to make sure that there are burls (that the variable burls is not empty) before calling your averageSize function. You will have done this check MANY times before now - think back to basic levels on attacking.
2 Likes
This should not be a problem since there is a constant stream of burls in this level but @reesylou is correct.
2 Likes
Righhhhhhhhhhht. Thanks for refreshing my memory, @reesylou and @_TD_RodYT
1 Like
This does not work for all the burls, because I don’t know what to compare burls.length
to.
# Senick is trying to find the elusive Burleous Majoris!
# But he doesn't know how big a Burleous Majoris would be...
# Find the average size of this burl population to use as a baseline!
# This function returns average size of all the burls in an array.
def averageSize(burls):
sum = sumSize(burls)
# Remember the average is the sum of the parts divided by the amount!
return sum / burls.length
# This function should return the sum of all the burls sizes.
def sumSize(burls):
# Implement the sum function using the burls 'size':
if burls.length > 15:
sum = sum(burls.size)
return sum
while True:
# Find the average size of the burls by calling the 'averageSize' function.
burls = hero.findByType("burl")
q = averageSize(burls)
# Say the average size of the seen burls!
hero.say(q)
1 Like
Make sure you read my last post.
In sumSize, you will need to create a for loop to find the total of every burl’s size combined.
sum = 0
for burl in burls:
sum = sum + burl.size
Then, in averageSize, the function will divide the total size by the amount of burls. (to find the average size)
(I don’t give out free code, but this level is a little confusing. I will delete this post when the devs change the Hints.)
1 Like
Thank you! I agree, the hints did not make sense.
1 Like
That worked! Thanks for the help, @reesylou and @_TD_RodYT!
2 Likes
def averageSize(burls):
sum = sumSize(burls)
return sum / len(burls)
def sumSize(burls):
sum = 0
for i in range(len(burls)):
burl = burls[i]
sum += burl.size
return sum
While True:
burls = hero.findEnemies()
avgSize = averageSize(burls)
hero.say(avgSize)
Can someone help out and tell me why this doesn’t work?
thanks