In: Computer Science
IN PYTHON Question B Considering how objects list in their own memory space and can behave almost like independent entities, think about some possible programs that you could create with this concept. (for example, a simulated worlds). Be specific in your description as to how OOP concepts would be employed.
#----------- ParellelWorlds.py ----------
'''
This is a sample code to describe how objects are
placed in their own memory
and how objects are independent to each other.
'''
from ctypes import c_int, addressof
#sample World class
class World:
#with name and incidents array that are occuring
in
#at that time.
#default constructor
def __init__(self):
self.name="None"
self.incidents = []
#parameterized constructor
def __init__(self,name,incidents):
self.name=name
self.incidents = incidents
#returns the to string format of the object.
def __str__(self):
res = "Hi, This is World:
"+self.name+"\n"
res += "Current Incidents in my
world\n"
for incident in
self.incidents:
res +=
str(incident) +"\n"
return res
#now create a set of incidents for two worlds
in120 = ["Barry Allen is a SpeedSter","Iris West is just a
Journelist","Barry Allen and his team flash are saving the
city"]
in1 = ["Barry Allen is just a Forencics officer at CCPD","Iris West
is a Police Officer"]
#create objects for two worlds
earth120 = World("Earth120",in120)
earth1 = World("Earth1",in1)
#print each world
print(earth120)
print(earth1)
'''
As you can see both the objects have different values at they are
run at same code.
The objects created will be stored at different locations.
Objects are independent to each other. how many objects you create
they won't depend on other one.
their memory is different and their values are stored in different
location.
'''