Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] The Spy Among Us

I don’t get anything please help me from the start.

# The inner gate can hold for a long time.
# However, one of these peasants is an OGRE SPY!
# There is a hint! The spy's name has the letter "z"

# This function checks for a specific letter in a word.
# A string is just an array! Loop over it like an array
def letterInWord(word, letter):
    for i in range(len(word)):
        character = word[i]
        # If character is equal to letter, return True
        if enemy:
            
    # The letter isn't in the word, so return False
    return False


spyLetter = "z"
friends = hero.findFriends()

for friend in friends:
    friendName = friend.id
    if letterInWord(friendName, spyLetter):
        # Reveal the spy!
        hero.say(friendName + " is a spy!")
    else:
        hero.say(friendName + " is a friend.")

Here check if character == letter and if so, then return True.
Do you need any more assistance at this level?

Andrei

1 Like

I don’t get what you are saying

First, check if character == letter and if that is true, then return True.
Do you need any more assistance at this level?

Andrei

2 Likes

Is this Right:

# The inner gate can hold for a long time.
# However, one of these peasants is an OGRE SPY!
# There is a hint! The spy's name has the letter "z"

# This function checks for a specific letter in a word.
# A string is just an array! Loop over it like an array
def letterInWord(word, letter):
    for i in range(len(word)):
        character = word[i]
        # If character is equal to letter, return True
        spyLetter = "z"
        if character == spyLetter:
            True
    # The letter isn't in the word, so return False
    return False


spyLetter = "z"
friends = hero.findFriends()

for friend in friends:
    friendName = friend.id
    if letterInWord(friendName, spyLetter):
        # Reveal the spy!
        hero.say(friendName + " is a spy!")
    else:
        hero.say(friendName + " is a friend.")

Here put

return True

Does it work now?

Andrei

1 Like
        if character == spyLetter:

spyLetter is not defined in this function. Use ‘letter’ instead.

1 Like

Congratulations for completing the level! :partying_face:

Andrei

1 Like