ValueError with for loop with two iterators Python -


i experimenting replacing block of if/ elif statements similar loop changes conditions of 1 loop few times.

my original if/ elif statements item system of rpg coding. each type of item can go in slots of inventory.

def pickupitem(self): #adds item inventory in space depending on type

if self.type == 1 , not inventory[0]: #type 1 weapon type, 2 shields, etc.         inventory[0] = self #sets weapon inventory slot object      elif self.type == 2 , not inventory[1]:         inventory[1] = self      elif self.type == 3 , not inventory[2]:         inventory[2] = self 

so, here code trying replace previous check each of if/ elif statements' pairs of conditions:

def pickupitem(self):    i, j in range(1, 4), range(3):         if self.type == , not inventory[j]:             inventory[j] = self 

i think should work, error:

    i, j in range(1, 4), range(0, 3): valueerror: many values unpack (expected 2) 

you can set j = - 1 in loop:

for in range(1,4):     j = - 1     if self.type == , not inventory[j]:         inventory[j] = self 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -