Help with ice hunter


#1

i dont see what im donig wrong

# Hunt for 4 yaks. Choose only the small ones.
# Small yak names contain a "bos" substring.

# This function checks if a word contains a substring.
def isSubstring(word, substring):
    # We iterate through the start indexes only.
    rightEdge = len(word) - len(substring)
    # Loop through the indexes of the word.
    for i in range(rightEdge + 1):
        # For each of them loop through the substring
        for j in range(len(substring)):
            # Use an offset for the word's indexes.
            shiftedIndex = i + j
            # If letters aren't the same:
            if word[shiftedIndex] != substring[j]:
                # Check the next start index in the word.
                break
            # If it was the last letter in the substring:
            if j == len(substring) - 1:
                # Then the substring is in the word.
                return True
    # We haven't found the substring in the word.
    return False

# Loop through all enemies.
enemies = hero.findEnemies()
for e  in range(len(enemies)):
    enemy = enemies[e]
    nearest = hero.findNearest(enemy)
    # Use the function isSubstring to check
    # if an enemy name (id) contains "bos":
    if nearest name (id) contanes "bos":
        
        # Then defeat it.
        hero.attack(enemy)

it keeps telling me to put a colin after

if nearest name (id) contanes "bos":

#2

please post link to the level?


#3

https://codecombat.com/play/level/ice-hunter?


#4

u dont do if nearest name (id) contanes "bos":
u do the isSubstring() thing
like u input the yak name for word, and the substring in substring
like this:
if u want to check whether the word applepen has the substring plep in it, then u do isSubstring("applepen", "plep")


#5

make sure to have a variable to contain the return value for isSubstring though.


#6

it still has the same problem as befor


#7

wate do you mean like this

# Hunt for 4 yaks. Choose only the small ones.
# Small yak names contain a "bos" substring.

# This function checks if a word contains a substring.
def isSubstring(word, substring):
    # We iterate through the start indexes only.
    rightEdge = len(word) - len(substring)
    # Loop through the indexes of the word.
    for i in range(rightEdge + 1):
        # For each of them loop through the substring
        for j in range(len(substring)):
            # Use an offset for the word's indexes.
            shiftedIndex = i + j
            # If letters aren't the same:
            if word[shiftedIndex] != substring[j]:
                # Check the next start index in the word.
                break
            # If it was the last letter in the substring:
            if j == len(substring) - 1:
                # Then the substring is in the word.
                return True
    # We haven't found the substring in the word.
    return False

# Loop through all enemies.
enemies = hero.findEnemies()
for e  in range(len(enemies)):
    enemy = enemies[e]
    # Use the function isSubstring to check
    # if an enemy name (id) contains "bos":
    if isSubstring(word, substring) contanes "bos":
        
        # Then defeat it.
        hero.attack(enemy)


#8

wate i got it thank you so mutch