[Solved] Help with aggressive mimicry


#1

this is my code

# Protect the village from the ogres. 
# Watch for ogres, peasants and ogres disguised as ”peasants".

# This function checks if the text starts with the word.
def startsWith(text, word):
    # If the word is longer then the text:
    if len(word) > len(text):
        return False
    # Loop through the indexes of word and text.
    for index in range(len(word)):
        # If characters with the same index are different:
        if word[index] != text[index]:
            # Then the word doesn't coincide with the text.
            return False
    # We checked all letters and they are the same.
    return True

ogreNameStart = "Zog"

while True:
    enemy = hero.findNearestEnemy()
    suspect = hero.findNearest(hero.findFriends())
    # Use the function "startsWith" to check
    # if suspect's name (id) starts with "Zog", attack:
    if suspect (id) startsWith "zog":
        hero.attack(enemy)
    else:
        if enemy:
            hero.attack(enemy)
        else:
            hero.move(27,27)

    

and it wants me to add a : after

  if suspect (id) startsWith "zog":```

#2

That doesn’t LITERALLY mean write if suspect (id) startsWith "zog"
It means to utilize the startsWith function defined before.


#3

i tried this but my hero wont realise that its an ork until it revels its self

# Protect the village from the ogres. 
# Watch for ogres, peasants and ogres disguised as ”peasants".

# This function checks if the text starts with the word.
def startsWith(text, word):
    # If the word is longer then the text:
    if len(word) > len(text):
        return False
    # Loop through the indexes of word and text.
    for index in range(len(word)):
        # If characters with the same index are different:
        if word[index] != text[index]:
            # Then the word doesn't coincide with the text.
            return False
    # We checked all letters and they are the same.
    return True

ogreNameStart = "Zog"

while True:
    enemy = hero.findNearestEnemy()
    suspect = hero.findNearest(hero.findFriends())
    # Use the function "startsWith" to check
    # if suspect's name (id) starts with "Zog", attack:
    if startsWith:
        if enemy:
            if hero.isReady("chain-lightning"):
                hero.cast("chain-lightning", enemy)
            else:
                
                hero.attack(enemy)
        else:
            hero.moveXY(27,27)

theres nothing wrong with the code exsept for the fact thai its faleing


#4

nvm i got it thank you