title: How do I resolve this python error: "TypeError: 'NoneType' object is not iterable"?
body: <p>How do I resolve this error?</p>
  
  <pre><code>Traceback (most recent call last):
  You attacked Magus for 291 points of damage.
    File "/Users/bill/Documents/Dev/PycharmProjects/Battle/main.py", line 189, in &lt;module&gt;
  
  spell, magic_dmg = enemy.choose_enemy_spell()
  </code></pre>
  
  <p>It's only happening sometimes. I'm at a loss as to why it only happens sometimes and why only sometimes this data is "NoneType".</p>
  
  <pre><code>for enemy in enemies:
      enemy_choice = random.randrange(0, 2)
  
      if enemy_choice == 0:
          target = random.randrange(0, 2)
          enemy_dmg = enemies[0].generate_damage()
  
          players[target].take_damage(enemy_dmg)
          print(enemy.name.replace("  ", "") + " attacks " + players[target].name.replace(" ", "") + " for", str(enemy_dmg) + ".")
  
      elif enemy_choice == 1:
          spell, magic_dmg = enemy.choose_enemy_spell()
          enemy.reduce_mp(spell.cost)
  
          if spell.type == "white":
              enemy.heal(magic_dmg)
              print(bcolors.OKBLUE + spell.name + " heals " + enemy.name.replace("  ", "") + " for", str(magic_dmg), "HP." + bcolors.ENDC)
          elif spell.type == "black":
  
              target = random.randrange(0, 2)
  
              players[target].take_damage(magic_dmg)
  
              print(bcolors.OKBLUE + "\n" + enemy.name.replace(" ", "") + "'s " + spell.name + " deals", str(magic_dmg),
                    "points of damage to " + players[target].name.replace("  ", "") + bcolors.ENDC)
  
              if players[target].get_hp() == 0:
                  print(players[target].name.replace("  ", "") + " has died.")
                  del players[player]
  </code></pre>
  
  <p>Here is the complete code: <a href="https://pastebin.com/2tztP4P4" rel="nofollow noreferrer">https://pastebin.com/2tztP4P4</a></p>