Question

In: Computer Science

IN PYTHON Question B Considering how objects list in their own memory space and can behave...

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.

Solutions

Expert Solution

#----------- 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.
'''


Related Solutions

Question B Considering how objects list in their own memory space and can behave almost like...
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.
python Write a function pack_to_5(words) that takes a list of string objects as a parameter and...
python Write a function pack_to_5(words) that takes a list of string objects as a parameter and returns a new list containing each string in the title-case version. Any strings that have less than 5 characters needs to be expanded with the appropriate number of space characters to make them exactly 5 characters long. For example, consider the following list: words = ['Right', 'SAID', 'jO'] The new list would be: ['Right', 'Said ', 'Jo '] Since the second element only contains...
Two objects, A and B, are released from rest in free space (no other masses are...
Two objects, A and B, are released from rest in free space (no other masses are near). Object A has a greater mass than object B. They accelerate toward each other under the action of their mutual gravitational attraction. a. On which object is the greater work done? b. At the instant just before they hit, which object will have the momentum with the greatest magnitude? c. At the instant just before they hit, which object will have the greater...
Can anyone use python to solve this problem: Part B: List of lists The aim of...
Can anyone use python to solve this problem: Part B: List of lists The aim of Part B is to learn to work with list of lists. You may want to open the file lab05b_prelim.py in the editor so that you can follow the task description. The first part of the file lab05b_prelim.py defines a variable called datasets. The variable datasets is a list of 4 lists. This part consists of 2 tasks. Task 1: We ask you to type...
If you have various objects in space, what does space look like? How does the universe...
If you have various objects in space, what does space look like? How does the universe evolve? Please explain your answer.
a) Explain how performance can be controlled in virtual memory. (b) How does the OS implement...
a) Explain how performance can be controlled in virtual memory. (b) How does the OS implement dynamic allocation of frames? c) Explain the main difficulty in using and/or managing virtual memory.
A. What are Objects? B. How do Objects differ from Classes? C. Where are Objects stored...
A. What are Objects? B. How do Objects differ from Classes? C. Where are Objects stored in Memory? D. Why do you not need to declare when you are finished using an Object in Java? E. Can you edits the contents of a String? View keyboard shortcuts EditViewInsertFormatToolsTable 12pt Paragraph
List the different ways the government can force monopolists to behave and price more competitively and...
List the different ways the government can force monopolists to behave and price more competitively and discuss the difference between Marginal Cost and Average Cost pricing between a natural monopolist and a regular monopolist.
Python Question Using lists, write the function non_unique(list) that takes a list list as argument. It...
Python Question Using lists, write the function non_unique(list) that takes a list list as argument. It returns a list which duplicated elements remains and each duplicated element is followed by a number which shows how many times it appears. All elements in return list should be in the same order as their appearance in the original list. For example, given the input [‘a’, ‘b’, ‘c’, ‘a’, ‘b’, ‘d’, ‘a’,‘e’], the function would return [‘a’, 3, ‘b’, 2]. Another example, ['abc',...
Python 3 question Suppose that a directed and weighted graph represented as vertex-list, how could it...
Python 3 question Suppose that a directed and weighted graph represented as vertex-list, how could it perform uniform cost search by using priority queue?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT