Point the error lines and explain why the code isnât right
Some lines can be deleted without affecting the running of the program - point them
why the lines 10 and 12 donât throw an error?
/ PS: quiz not for Deadpool198, brooksy125 or jka2706 , but if they want to answer the question 3 they can PM me /
PS: As you may already know, all off-topic addicts are on my ignore list. For example, there are all current Regularâ's If someone is on this list and he / she gives the correct answer to all the questions, the ârewardâ will be the removal from it
Youâre saying that if there is a string, you command your friends to attack the enemy that has that id? On lines 13 and 15. That means theyâre going to attack the enemy Skully always because there is always a string Skully.
Thatâs much, much better⌠So implementing your idea:
def findEnemy(id):
for enemy in hero.findEnemies():
if enemy.id == id:
return enemy
#####################################################################
elif ogre.health <= 0:
Rusty = findEnemy('Rusty')
Skully = findEnemy('Skully')
if Rusty :
hero.command(friend, "attack", Rusty) # do not attack "String", it's a bad
elif Skully:
hero.command(friend, "attack", Skully) # bad idea even if it works :-)
But it doesnât affect the functioning of the program, so too many errors remainâŚ
PS. i think this function is more versatile:
def findUnit(id, units):
for unit in units:
if unit.id == id:
return unit
Gorgin = findUnit("Gorgin", hero.findFriends()) # calling the function
I would like you to change your program commandPaladin(friend) so when the witch is dead, she attacks the skeletons instead of like almost everyone dying.
No, No! Itâs not my program - hereâs the video of my solution done years ago: player.vimeo.com/video/420089413?
This program is only a tool for refining the debugging skills and a user has passed the level with this code ( I was truly astonished how itâs possible to write something so wrong and to succeed - itâs pure magic
Yes, you can change the commandPaladin(friend), but first find all the errors in commandTroops().
So till now we have:
def findEnemy(id):
for enemy in hero.findEnemies():
if enemy.id == id:
return enemy
1 def commandTroops():
2 friends = hero.findFriends()
3 # paladins = hero.findByType("paladin") not needed
4 # enemies = hero.findEnemies() not needed
5 # witches = hero.findByType("witch") not needed
6 # enemies = hero.findEnemies() not needed
7 ogre = hero.findByType("ogre", hero.findEnemies())
8 for friend in friends:
9 if friend.type != 'paladin':
10 if ogre.health > 0:
11 hero.command(friend, "attack", "Oni")
12 elif ogre.health <= 0:
13 # if 'Rusty' : wrong
14 # hero.command(friend, "attack", "Rusty") replaced
15 # elif 'Skully': wrong
16 # hero.command(friend, "attack", "Skully") replaced
Rusty = findEnemy('Rusty')
Skully = findEnemy('Skully')
if Rusty :
hero.command(friend, "attack", Rusty)
elif Skully:
hero.command(friend, "attack", Skully)
17 else:
18 commandPaladin(friend)
There are still errors but combining them the function works somehow
lines 24 and 25 aren 't executed
If you donât know why the current hero.command() gurus are Deadpool and brooksy so serch in their posts.
/I was really amazed by the minions intelligence to go around the wall. I always did it with three-point maneuver /
But we have 2 more errors in commandTroops(), the first is easy to spot, the second is the cherry on the top