Food Magnate Simulation questions
You have been given the code for the Food Magnate Simulation. Using that code, answer the following questions:
N.B. this code was rewritten from the original by me during the summer so it conforms to the Python style guide. Most names have been recased from PascalCase to snake_case
-
State the name of an identifier for:
- An attribute in the
Settlement
class that is only accessible to subclasses ofSettlement
.- N/A, because this is Python and all attributes are accessible by all objects (the 'consenting adults' principle). However, an attribute that is considered non-public by convention is
Settlement._x_size
- N/A, because this is Python and all attributes are accessible by all objects (the 'consenting adults' principle). However, an attribute that is considered non-public by convention is
- A subclass
LargeSettlement
- A subroutine from the
Company
class that cannot be called from outside theCompany
class.- Again, N/A due to the 'consenting adults' principle. However, a subroutine of
Company
that by convention is considered non-public is the static methodCompany._get_distance_between_two_outlets
- Again, N/A due to the 'consenting adults' principle. However, a subroutine of
- A string method called from the
company_index
subroutine in theSimulation
classstr.lower
- An attribute in the
-
'10' Add an option to run the simulation for many days (>1)
-
'11' Add a new
SmallSettlement
class and an option to create a small settlement in the simulation launch menu.- Your PROGRAM SOURCE CODE for the amended
- SCREEN CAPTURE(S) showing the results of the requested change
- <script id="asciicast-lzwMKAPq7GPrsUgd2DZqMuQgJ" src="https://asciinema.org/a/lzwMKAPq7GPrsUgd2DZqMuQgJ.js" async>
- '1' This question refers to the subroutine
_process_add_households_event
and the_display_events_at_day_end
subroutine within theSimulation
class.
Modify the subroutine
_process_add_households_event
in theSimulation
class. Rename the subroutine to_process_add_remove_households_event
and all calls to it so that they use the new identifier. Instead of just adding 1-4 houses to the settlement, there should be a 30% chance that 1-4 houses will leave the settlement instead.The message displayed by the subroutine should be changed so that when houses are removed, it says removed from instead of added to.
Modify the subroutine
_display_events_at_day_end
in the Simulation class. The subroutine should always call the newly modified subroutine_process_add_remove_households_event
.Test the changes that you have made work:
- run the Skeleton Program
- leave the first prompt blank, to indicate a normal-sized settlement
- enter D at the next prompt for default companies
- enter 6 for 'advance to next day'
- enter 1 for 'display details of households'
- repeat this until households are removed from the settlement (and are added)