# Get all your troops to the end of the path by passing over the mines.
# You can locate duds by finding the mines that have a value that is a prime number.
# Check the guide for clarification.
while True:
traps = hero.findByType("fire-trap")
trapsIndex = 0
for trap in traps:
trap = trap[trapsIndex]
trap.value = value
for i in range(2, Math.ceil(Math.sqrt(value))):
if n % i == 0:
hero.move(trap.pos)
else:
trapsIndex += 1

I get an error message that I canât write a property of a non-object type which is value. Itâs on the line trap.value = value. Any help someone can give me?

You have to get your method straight.
Are you using for trap in traps or traps[trapsIndex]. At the moment youâve got for trap in traps, which defines trap, but for some reason youâre also defining trap as trap[trapsIndex]. Thatâs incorrect because trap isnât an array, thatâs traps.
Also what is n? have you defined it?
Danny

# Get all your troops to the end of the path by passing over the mines.
# You can locate duds by finding the mines that have a value that is a prime number.
# Check the guide for clarification.
while True:
traps = hero.findByType("fire-trap")
trapsIndex = 0
for trap in traps:
value = trap.value
for i in range(2, Math.ceil(Math.sqrt(value))):
if value % i == 0:
hero.moveXY(hero.pos.x, trap.pos.y)
hero.move(trap.pos)
else:
continue

Well now Iâve changed it a little more and now have

# Get all your troops to the end of the path by passing over the mines.
# You can locate duds by finding the mines that have a value that is a prime number.
# Check the guide for clarification.
while True:
traps = hero.findByType("fire-trap")
for trap in traps:
value = trap.value
for i in range(2, Math.ceil(Math.sqrt(value))):
if value % i == 0:
hero.moveXY(trap.pos.x + 10, trap.pos.y)
hero.move(trap.pos)
else:
i += 1

This is quite a hard level - it took me a lot of attempts to get through it. A couple of things to get you started:

At the moment youâre finding all of the fire-traps (or at least all the ones in range of your glasses). Is that what you want?

Youâre on the right lines for how to find a prime number. But think carefully about what âif value % i == 0â actually means. Is value a prime number if this is true?
I made the âcheck if a number is primeâ into a function, so it could all run before my hero took any action.

Try getting these things sorted so your hero can get through the first set of fire-traps. Once you have the basics working there will then be some more problems to solve.

# Get all your troops to the end of the path by passing over the mines.
# You can locate duds by finding the mines that have a value that is a prime number.
# Check the guide for clarification.
def isItPrime(number):
for i in range(2, Math.ceil(Math.sqrt(number))):
if number % i != 0:
return True
else:
i += 1
while True:
traps = hero.findNearest(hero.findByType("fire-trap"))
for trap in traps:
value = trap.value
isItPrime(value)
if isItPrime(value) == True:
hero.move(trap.pos)
else:
pass

I donât see what you mean by finding all of the fire-traps. Would I have to see the ones that closest, like in the code up there ^^^ with hero.findNearest(hero.findByType("fire-trap")) AND I have a infinite loop. I know that I have to command the troops, but I donât want to worry about that yet.

Have another look at your isItPrime function. Youâre thinking on the right lines, but what happens if you put 15 into the function? i starts at 2; and 15 % 2 = 1, which doesnât equal 0; so the function returns True. Is that right?

I donât think you want the i += 1 in there as the for loop will increase i each time - I suspect this is what is causing the errors.

In terms of finding the closest fire-traps, you could just restrict them by distanceâŚ

Keep going with it - you sound as though youâve got a structure and youâre working through each problem as you come to it (which seem to be the key to programming).

#Commented out to stop infinite loop.
# Get all your troops to the end of the path by passing over the mines.
# You can locate duds by finding the mines that have a value that is a prime number.
# Check the guide for clarification.
def isItPrime(number):
for i in range(2, number):
if number % i != 0:
return True
while True:
traps = hero.findNearest(hero.findByType("fire-trap"))
for trap in traps:
if trap:
value = trap.value
isItPrime(value)
if isItPrime(value) == True:
hero.move(trap.pos)
else:
continue

hmmmm, now it says that in trap.pos, trap is not defined

numbs = [77, 3, 11, 21, 42, 55, 51]
def isItPrime(number):
for i in range(2, number):
if number % i != 0:
print( str(i) + " " + str(number) + " " + str(number % i))
return True
for num in numbs:
if isItPrime(num):
print(num)
# shorturl.at/mxHL4 shortcut from http://www.pythontutor.com

So you must write a better isItPrime() function or find one in internet ( and there is nothing wrong doing it
Shotrcut where the code can be run http://shorturl.at/mxHL4
P.S. For years I check snippets of codecombat code in http://www.pythontutor.com

Ok. I found a different one on the web .But, now itâs the moving part. I donât move anywhere. Here Iâll show it again.

Code

#Commented out to stop infinite loop.
# Get all your troops to the end of the path by passing over the mines.
# You can locate duds by finding the mines that have a value that is a prime number.
# Check the guide for clarification.
def isItPrime(n):
if n <= 1 or n % 1 > 0:
isPrime = False
for i in range(2, n/2):
if n % i == 0:
isPrime = False
return False
else:
isPrime = True
return True
while True:
traps = hero.findNearest(hero.findByType("fire-trap"))
for trap in traps:
if trap:
value = trap.value
isItPrime(value)
if isItPrime(value) == True:
hero.move(trap.pos)
else:
continue