Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Traceback (most recent call last):
- File "test.py", line 32, in <module>
- invoker = Hero("Invoker")
- File "test.py", line 14, in __init__
- Alive.__init__(self)
- File "test.py", line 9, in __init__
- self.id = totalId + 1
- UnboundLocalError: local variable 'totalId' referenced before assignment
- import random
- totalId = -1
- class Alive:
- def __init__(self):
- teams = ["Honor", "BlackLoop"]
- self.team = random.choice(teams)
- self.id = totalId + 1
- totalId = totalId + 1
- class Hero(Alive):
- def __init__(self, name = "default", lvl = 1):
- Alive.__init__(self)
- self.lvl = lvl
- self.name = name
- def lvlUp(self, count = 1):
- self.lvl = self.lvl + count
- def getInfo(self):
- print(f"{'*' * 20}nId_{self.id}nName: {self.name}nTeam: {self.team}nLevel: {self.lvl}n{'*' * 20}nn")
- class Soldier(Alive):
- def followTheHero(self):
- pass
- if __name__ == "__main__":
- honor = []
- blackloop = []
- invoker = Hero("Invoker")
- void = Hero("Void")
- invoker.getInfo()
- void.getInfo()
- class Alive:
- def __init__(self):
- global totalId ##### нужно добавить #####
- teams = ["Honor", "BlackLoop"]
- self.team = random.choice(teams)
- self.id = totalId + 1
- totalId = totalId + 1
- class Alive:
- total_id = -1
- def __init__(self):
- teams = ["Honor", "BlackLoop"]
- self.team = random.choice(teams)
- Alive.total_id += 1
- self.id = Alive.total_id
Add Comment
Please, Sign In to add comment