I am trying to do the echo of war level. I’m trying to use the string.contains() method but am getting the following error (I know I could do this by iterating through the characters of the string in a loop but I want to understand why the string.contains() is not working)
# Destroy 5 robobombs. Some of them are old and safe.
# Old (safe) bombs have the certain letter in their id.
# This function checks if searchLetter is in searchWord.
def isLetterInWord(searchWord, searchLetter):
# Complete the function.
if searchWord.contains(searchLetter):
return True
return False
# The engineer knows how the old robots are marked.
engineer = hero.findFriends()[0]
safeLetter = engineer.safeLetter
enemies = hero.findEnemies()
for index in range(len(enemies)):
enemy = enemies[index]
if enemy and isLetterInWord(enemy.id, safeLetter):
# Destroy the enemy if it's safe.
while enemy.health > 0:
hero.attack(enemy)
I want to know what I’m doing wrong with contains not an alternative solution to the problem please (which I know how to do)
def contains (word, letters):
for i in range(len(word)):
e = None
for j in range(len(letters)):
if word[i + j] == letters[j]:
continue
e = 0
break
if e == None:
return True
return False
no this would return a boolean (true or false) it’s not the index if that’s what you were looking for… I don’t think you can use hero.say with a boolean