title: Organizing multiple switching characters with health bars in python
body: <p>I am trying to make a 2 player text-based pokemon battle replica with multiple pokemon in it that can be switched out and have their own health and moves.  </p>
  
  <p>I have successfully made a similar script where one person fought against the computer where the computer player did basically nothing and there was also only one pokemon per player. Now I am trying to expand on that by making it so that two people can fight each other on the same device, playing hot seat style.  </p>
  
  <p>The problem I'm having is that I have yet to find a way to organize and call back each individual pokemon while the players switch around which one is the active one.  I have tried using dictionaries, but they are not very useful when I want to damage the pokemon, because I cannot seem to change the value in each heath bar when using them.  I have not yet tried to make a dictionary for each individual pokemon, just one per player containing them.  </p>
  
  <p>But the problem with having individual dictionaries, is that I need a way to tell how many pokemon are left on each team.  There are three per team, and the battle ends when one team is completely wiped out.  </p>
  
  <p>Any help would be appreciated.  I'll leave my original Player VS. Computer script here for reference:</p>
  
  <pre><code>import time
  Hm=150
  Hr=60
  TackleMove=50
  ScratchMove=40
  BiteMove=60
  #Intro
  print 'Difficulty? Type "Easy", "Normal", "Hard"'
  EsMo = input("Answer: ")   
  print "A wild Magikarp appeared!"
  time.sleep(0.5)
  print "Go! Rattata!"
  time.sleep(0.5)
  
  #Using a move
  def PlayerTurn():
      print 'Moves are: "Tackle", "Scratch", "HyperFang", "Bite"'
      time.sleep(0.5)
      Move = input("Use: ")
      #Tackle
      if Move is "Tackle":
          print "Rattata used Tackle!"
          global Hm
          Hm-=TackleMove
          time.sleep(0.5)
          if EsMo is "Hard":
              pass
          elif EsMo is "Easy" or "Normal":
              print "Magikarp has", Hm, "HP Left"
  
      #Scratch
      elif Move is "Scratch":
          print "Rattata used Scratch!"
          Hm-=ScratchMove
          time.sleep(0.5)
          if EsMo is "Hard":
              pass
          elif EsMo is "Easy" or "Normal":
              print "Magikarp has", Hm, "HP Left"
  
      #HyperFang
      elif Move is "HyperFang":
          print "Rattata used HyperFang!"
          Hm/=2
          time.sleep(0.5)
          if EsMo is "Hard":
              pass
          elif EsMo is "Easy" or "Normal":
              print "Magikarp has", Hm, "HP Left"
  
      #Bite
      elif Move is "Bite":
          print "Rattata used Bite!"
          Hm-=BiteMove
          time.sleep(0.5)
          if EsMo is "Hard":
              pass
          elif EsMo is "Easy" or "Normal":
              print "Magikarp has", Hm, "HP Left"
  
      #Cheat
      elif Move is "Cheat":
          print "CHEATER!"
          Hm-=Hm
          print "Magikarp has", Hm, "HP Left"
      else:
          print "Oops"
      return
  
  #AI Turn
  def AITurn():
      if Hm&gt;50 or EsMo is "Easy":
          print "Magikarp used Splash!"
          time.sleep(1)
          print "But nothing happened..."
      elif Hm&lt;=50 and EsMo is "Normal" or "Hard":
          print "Magikarp used Tackle!"
          global Hr
          Hr-=TackleMove
          time.sleep(1)
          print "Rattata has", Hr, "HP Left"
      else:
          print "Oops"
      return
  
  #Full Loop
  while Hm&gt;0:
      #Action Choice
      print 'Actions are: "Fight", "Pokeball", "Run"'
      time.sleep(0.5)
      Action = input("What do you want to do?: ")
      time.sleep(0.5)
      #If Choose Fight
      if Action is "Fight":
          PlayerTurn()
          if Hm&lt;=0:
              time.sleep(1)
              print "Magikarp Fainted!"
              time.sleep(1)
              print "You Win!"
              break
          time.sleep(0.5)
          AITurn()
          if Hm&lt;=0:
              time.sleep(1)
              print "Magikarp Fainted!"
              time.sleep(1)
              print "You Win!"
              break
          elif Hr&lt;=0:
              time.sleep(1)
              print "Rattata Fainted!"
              time.sleep(1.5)
              print "You Lost!"
              break
          time.sleep(0.5)
          continue
      #If Choose Run
      if Action is "Run":
          print "Ran away Safley!"
          break
      #If Choose Pokeball
      if Action is "Pokeball":
          time.sleep(0.5)
          print "You threw the Pokeball!"
          time.sleep(1)
          if Hm&gt;100:
              print "..."
              time.sleep(1)
              print "Darn! It Broke Free!"
          elif 50&lt;Hm&lt;=100:
              print "..."
              time.sleep(1)
              print "..."
              time.sleep(1)
              print "Almost had it!"
          elif 30&lt;Hm&lt;=50:
              print "..."
              time.sleep(1)
              print "..."
              time.sleep(1)
              print "..."
              time.sleep(1)
              print "Shoot! So Close!"
          elif Hm&lt;=30:
              print "..."
              time.sleep(1)
              print "..."
              time.sleep(1)
              print "..."
              time.sleep(1)
              print "You Caught a Magikarp!"
              time.sleep(1.5)
              print "Congratulations!"
              break
          else:
              print "Oops"
          time.sleep(1)
          AITurn()
          if Hm&lt;=0:
              time.sleep(1)
              print "Magikarp Fainted!"
              time.sleep(1)
              print "You Win!"
              break
          elif Hr&lt;=0:
              time.sleep(1)
              print "Rattata Fainted!"
              time.sleep(1.5)
              print "You Lost!"
              break
          time.sleep(0.5)
          continue
  time.sleep(2)
  print "Please, try again!"
  #End
  </code></pre>
  
  <p>My current code is in two forms and is still being worked out so I have some things more complete than others.  In this instance, I only have Rattata's stuff filled out, and the move that I'm testing with is Scratch.</p>
  
  <pre><code>import time
  P1Rat=50
  P1Abra=100
  P1Pidgey=100
  P2Rat=50
  P2Abra=100
  P2Pidgey=100
  Play1PokeSt=["Rattata", "Abra", "Pidgey"]
  ActPl1Poke=[]
  ActPl1PokeSt=[]
  Play2PokeSt=["Rattata", "Abra", "Pidgey"]
  ActPl2Poke=[]
  ActPl2PokeSt=[]
  
  #Player 1's Rattata Attacks
  def Rattata1():
      global ActPl2Poke
      print 'Moves are: "Tackle", "Scratch", "HyperFang", "Bite"'
      time.sleep(0.5)
      R1Move = input("Use: ")
      #Tackle
      if R1Move is "Tackle":
          print "Rattata used Tackle!"
          ActPl2Poke[0]-=50
  
      #Scratch
      elif R1Move is "Scratch":
          print "Rattata used Scratch!"
          ActPl2Poke[0]-=40
          print ActPl2Poke[:]
          print P2Rat
  
      #HyperFang
      elif R1Move is "HyperFang":
          print "Rattata used HyperFang!"
          ActPl2Poke[0]/=2
  
      #Bite
      elif R1Move is "Bite":
          print "Rattata used Bite!"
          ActPl2Poke[0]-=60
  
  def Play1Sel():
      while True:
          print "What Pokemon do you want to use?"
          print "Remaining Pokemon are:"
          print ", ".join(Play1PokeSt)
          Pokemon1=input()
          if Pokemon1 is "Rattata" and "Rattata" in Play1PokeSt:
              del ActPl1Poke[:]
              ActPl1Poke.append(int(P1Rat))
              del ActPl1PokeSt[:]
              ActPl1PokeSt.append("Rattata")
              break
          elif Pokemon1 is "Rattata" and "Rattata" not in Play1PokeSt:
              print "Rattata has fainted! Choose another!"
              continue
          if Pokemon1 is "Abra" and "Abra" in Play1PokeSt:
              del ActPl1Poke[:]
              ActPl1Poke.append(P1Abra)
              del ActPl1PokeSt[:]
              ActPl1PokeSt.append("Abra")
              break
          elif Pokemon1 is "Abra" and "Abra" not in Play1PokeSt:
              print "Abra has fainted! Choose another!"
              continue
          if Pokemon1 is "Pidgey" and "Pidgey" in Play1PokeSt:
              del ActPl1Poke[:]
              ActPl1Poke.append(P1Pidgey)
              del ActPl1PokeSt[:]
              ActPl1PokeSt.append("Pidgey")
              break
          elif Pokemon1 is "Pidgey" and "Pidgey" not in Play1PokeSt:
              print "Pidgey has fainted! Choose another!"
              continue
  
  
  def Play2Sel():
      while True:
          print "What Pokemon do you want to use?"
          print "Remaining Pokemon are:"
          print ", ".join(Play2PokeSt)
          Pokemon2=input()
          if Pokemon2 is "Rattata" and "Rattata" in Play2PokeSt:
              del ActPl2Poke[:]
              ActPl2Poke.append(P2Rat)
              del ActPl2PokeSt[:]
              ActPl2PokeSt.append("Rattata")
              break
          elif Pokemon2 is "Rattata" and "Rattata" not in Play2PokeSt:
              print "Rattata has fainted! Choose another!"
              continue
          if Pokemon2 is "Abra" and "Abra" in Play2PokeSt:
              del ActPl2Poke[:]
              ActPl2Poke.append(P2Abra)
              del ActPl2PokeSt[:]
              ActPl2PokeSt.append("Abra")
              break
          elif Pokemon2 is "Abra" and "Abra" not in Play2PokeSt:
              print "Abra has fainted! Choose another!"
              continue
          if Pokemon2 is "Pidgey" and "Pidgey" in Play2PokeSt:
              del ActPl2Poke[:]
              ActPl2Poke.append(P2Pidgey)
              del ActPl2PokeSt[:]
              ActPl2PokeSt.append("Pidgey")
              break
          elif Pokemon2 is "Pidgey" and "Pidgey" not in Play2PokeSt:
              print "Pidgey has fainted! Choose another!"
              continue
  #Player 2's Rattata Attacks
  def Rattata2():
      global ActPl2Poke
      print 'Moves are: "Tackle", "Scratch", "HyperFang", "Bite"'
      time.sleep(0.5)
      R2Move = input("Use: ")
      #Tackle
      if R2Move is "Tackle":
          print "Rattata used Tackle!"
          ActPl1Poke[0]-=50
  
      #Scratch
      elif R2Move is "Scratch":
          print "Rattata used Scratch!"
          ActPl1Poke[0]-=40
          print P1Rat
  
  
      #HyperFang
      elif R2Move is "HyperFang":
          print "Rattata used HyperFang!"
          ActPl1Poke[0]/=2
  
      #Bite
      elif R2Move is "Bite":
          print "Rattata used Bite!"
          ActPl1Poke[0]-=60        
  
  #Player 1's Turn
  def Play1():
      print "Actions are: Fight, Change"
      time.sleep(0.5)
      Act1=input("What do you want to do?: ")
      if Act1 is "Fight" and str(*ActPl1PokeSt) is "Rattata":
          Rattata1()
      elif Act1 is "Change":
          Play1Sel()
      else:
          print "oops"
  
  
  #Player 2's Turn
  def Play2():
      print "Actions are: Fight"
      time.sleep(0.5)
      Act2=input("What do you want to do?: ")
      if Act2 is "Fight" and str(*ActPl2PokeSt) is "Rattata":
          Rattata2()
      else:
          print "oops"
  
  #Whole Loop
  print "Player 1! Select Your Pokemon!"
  Play1Sel()
  print ActPl1Poke
  print "Player 2! Select Your Pokemon!"
  Play2Sel()
  print ActPl2Poke
  while True:
      print "Player 1, your turn."
      Play1()
      if P1Rat &lt;=0 or P2Rat &lt;=0:
          print "Finish"
          break
      else:
          print "Player 2, your turn."
          Play2()
          if P1Rat &lt;=0 or P2Rat &lt;=0:
              print "Finish"
              break
          continue
  </code></pre>
  
  <p>And then this is the other version:</p>
  
  <pre><code>import time
  
  Poke1={"Rattata" : 100 , "Abra" : 100 , "Pidgey" : 100}
  Poke2={"Rattata" : 100 , "Abra" : 100 , "Pidgey" : 100}
  ActPo1={}
  ActPo2={}
  
  #Player 1's Rattata's Moves
  def RattataAtk1():
      print 'Moves are: "Tackle", "Scratch", "HyperFang", "Bite"'
      time.sleep(0.5)
      MoveR1 = input("Use: ")
      #Tackle
      if MoveR1 is "Tackle":
          print "Rattata used Tackle!"
          ActPo2-=50
  
      #Scratch
      elif MoveR1 is "Scratch":
          print "Rattata used Scratch!"
          ActPo2-=40
  
      #HyperFang
      elif MoveR1 is "HyperFang":
          print "Rattata used HyperFang!"
          ActPo2/=2   
  
      #Bite
      elif MoveR1 is "Bite":
          print "Rattata used Bite!"
          ActPo2-=60
  
  #Player 2's Rattata's Moves
  def RattataAtk2():
      print 'Moves are: "Tackle", "Scratch", "HyperFang", "Bite"'
      time.sleep(0.5)
      MoveR2 = input("Use: ")
      #Tackle
      if MoveR2 is "Tackle":
          print "Rattata used Tackle!"
          ActPo1-=50
  
      #Scratch
      elif MoveR2 is "Scratch":
          print "Rattata used Scratch!"
          ActPo1-=40
  
      #HyperFang
      elif MoveR2 is "HyperFang":
          print "Rattata used HyperFang!"
          ActPo1/=2   
  
      #Bite
      elif MoveR2 is "Bite":
          print "Rattata used Bite!"
          ActPo1-=60
  
  
  #Selection of Player 1's Pokemon
  def Play1Sel():
      while True:
          print "What Pokemon do you want to use?"
          print "Remaining Pokemon are:"
          print Poke1.keys()
          Choose1=input()
          if Choose1 is "Rattata" and "Rattata" in Poke1:
              ActPo1["Rattata"]=Poke1["Rattata"]
              break
          else:
              print "Oops"
              break
  
  #Selection of Player 2's Pokemon
  def Play2Sel():
      while True:
          print "What Pokemon do you want to use?"
          print "Remaining Pokemon are:"
          print Poke2.keys()
          Choose2=input()
          if Choose2 is "Rattata" and "Rattata" in Poke2:
              ActPo2["Rattata"]=Poke2["Rattata"]
              break
          else:
              print "Oops"
              break
  
  #Player 1's Choice of Action
  def Play1():
      print "Actions are: Fight, Change"
      time.sleep(0.5)
      Act1=input("What do you want to do?: ")
      if Act1 is "Fight" and ActPo1.has_key("Rattata") is True:
          RattataAtk1()
      else:
          print "Oops"
  
  #Player 2's Choice of Action
  def Play2():
      print "Actions are: Fight, Change"
      time.sleep(0.5)
      Act2=input("What do you want to do?: ")
      if Act2 is "Fight" and ActPo2.has_key("Rattata") is True:
          RattataAtk2()
      else:
          print "Oops"
  
  #Full Loop
  print "Player 1! Select Your Pokemon!"
  Play1Sel()
  print ActPo1.items()
  print "Player 2! Select Your Pokemon!"
  Play2Sel()
  print ActPo2.items()
  while True:
      print "Player 1, your turn."
      Play1()
      if ActPo1.values()is 0:
          print "Finish"
          break
      else:
          print "Player 2, your turn."
          Play2()
          if ActPo2.values()is 0:
              print "Finish"
              break
          continue
  </code></pre>