The basic idea of the code is that agents come into the world, they age and then die. I want to keep track of who is dead and who is alive. Eventually, they will do more things but I think there should be a lot of things I am not doing best practice on. I assume I'm doing something wrong with "Global" as well.
# Classes
class Agent(object):
def __init__(self, identification, productivity, wealth, preferences, age, health, alive, sex):
self.identification = identification
self.productivity = productivity
self.wealth = wealth
self.preferences = preferences
self.age = age
self.health = health
self.alive = alive
self.sex = sex
def description(self):
print("My id is", self.identification)
print("My age is", self.age)
def Create_agents():
global id
alive.append(Agent(id,100,20,"blue",30,0,True,True ))
id += 1
# functions
def Initialize():
for x in range(3):
Create_agents()
def Death():
temp = alive.copy()
for agent in temp:
if agent.age>30:
agent.alive = False
print("Death of", agent.identification)
dead.append(agent)
alive.remove(agent)
def Time_skip():
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%SKIPPING TIME%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
global year
year += 1
print("The new year is", year)
for agent in alive:
agent.age +=1
Create_agents()
Death()
# Values
alive = []
dead = []
id = 0
year = 0
Initialize()
# Testing
for agent in alive:
agent.description()
Time_skip()
for agent in alive:
agent.description()
The output is:
My id is 0
My age is 30
My id is 1
My age is 30
My id is 2
My age is 30
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%SKIPPING TIME%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The new year is 1
Death of 0
Death of 1
Death of 2
My id is 3
My age is 30
temp = alive.copy()
change. \$\endgroup\$ – Peilonrayz May 16 '20 at 18:01