I need help with my code. It has an error for the sample/set up code, right here -
rightEdge = len(word) - len(substring)
My full code -
def isSubstring(word, substring):
rightEdge = len(word) - len(substring)
for i in range(rightEdge + 1):
for j in range(len(substring)):
shiftedIndex = i + j
if word[shiftedIndex] != substring[j]:
break
if j == len(substring) - 1:
return True
return False
enemies = hero.findEnemies()
for e in range(len(enemies)):
enemy = enemies[e]
isSubstring()
if enemy.id == "bos":
hero.attack("bos")
so here is the problem, as you said, isSubstring should take in 2 parameters, the word and the substring, so the word must be the enemy’s id, and the sub string should be “bos”, so here is the thing, you need to call the isSubstring function in the if statement, how it might look like:
if subString(enemy.id, "whatever the substring is") == True:
#Do something
So I tried that, and I would hit each yak once, and then stop. So I figured I would need a while true look to fix it. And it still stops. The annoying part is that each yak is at about only 15 health.
def isSubstring(word, substring):
rightEdge = len(word) - len(substring)
for i in range(rightEdge + 1):
for j in range(len(substring)):
shiftedIndex = i + j
if word[shiftedIndex] != substring[j]:
break
if j == len(substring) - 1:
return True
return False
enemies = hero.findEnemies()
for e in range(len(enemies)):
while True:
enemy = enemies[e]
if isSubstring(enemy.id, "bos"):
if enemy.health >= 0:
hero.attack(enemy)
break