Hello guys. It seems as if when you hit one problem and you solve it (with help), Problem seems to bite back at you as soon as you move on. I am currently stuck on Guess My Number, the first level in the Glacier. I have scoured the whole forum looking for a solution so, as my last resort, I decided to ask for help. If you have done this level then you might understand the problem - I don’t seem to be getting the right number. Here is my code:
def round(num):
return Math.round(num)
lowestPossible = 1
highestPossible = 999
num = 500
hero.say(num)
while True:
# You need to defeat the enemy before the next attempt.
enemy = hero.findNearest(hero.findEnemies())
if enemy:
# "scout" is 'greater', "munchkin" is less.
# Prepare for the next attempt and wipe out the ogre.
if enemy.type == "munchkin":
highestPossible = num
else:
lowestPossible = num
hero.attack(enemy)
sum = lowestPossible + highestPossible
if (sum / 2) == 1:
sum += 1
num = round(sum / 2)
else:
# Make your next attempt and say it.
hero.say(num)
Is it the first level? It looks like it’s right in the middle to me. I think the levels before it should go first.
I would recommend doing the bottom levels first, then go to the right with Kelvintaph Burgler etc. and move left until you get to the top left corner.
Danny
Hmm that is very peculiar. As soon as I started up the Glacier for the first time, the yellow arrow points to this level, which is bang in the middle! So yes @Deadpool198 this is the first level.
Elijah
Okay… I’m just saying this level builds on stuff leaned in previous levels. I don’t know why it has come up first, but normally you would start somewhere else.
Anyway your code is almost right.
Why are you rounding the num variable? The riddler didn’t ask specifically for a whole number…
As @Deadpool198 says, it might be easier to come back to this level in a bit. But having said that, I found that some of the Glacier levels are a step up in terms of difficulty, and there isn’t always as much help in the instructions and hints.
In terms of your code:
I used Math.floor() rather than Math.round() - I had to change that in yours to make it work
Everything after hero.attack(enemy) should be in the final ‘else’ statement.
I’m not sure what your final if statement is for, I got rid of that as well
There’s something odd going on with the variable ‘sum’ that the Riddler doesn’t like. When I got rid of the variable, and defined ‘num’ in terms of lowestPossible and highestPossible, the code started working. This might be because sum is a function in Python, and it’s confusing the code (maybe??).
Hope that helps, good luck with the rest of the Glacier!
Thanks @jka2706. I did what you said but my hero just keeps on saying 500, especially after I removed the final if statement. Here is my code:
def floor(num):
return Math.floor(num)
lowestPossible = 1
highestPossible = 999
num = 500
while True:
# You need to defeat the enemy before the next attempt.
enemy = hero.findNearest(hero.findEnemies())
if enemy:
# "scout" is 'greater', "munchkin" is less.
# Prepare for the next attempt and wipe out the ogre.
if enemy.type == "munchkin":
highestPossible = num
else:
lowestPossible = num
hero.attack(enemy)
else:
# Make your next attempt and say it.
hero.say(num)