Solution - Maze Population

The solution notebook can be downloaded from:

https://anaconda.org/ucl-rits/module12-mazepopulationsolution/notebook

With this maze structure:

house = {
    'living' : {
        'exits': {
            'north' : 'kitchen',
            'outside' : 'garden',
            'upstairs' : 'bedroom'
        },
        'people' : ['James'],
        'capacity' : 2
    },
    'kitchen' : {
        'exits': {
            'south' : 'living'
        },
        'people' : [],
        'capacity' : 1
    },
    'garden' : {
        'exits': {
            'inside' : 'living'
        },
        'people' : ['Sue'],
        'capacity' : 3
    },
    'bedroom' : {
        'exits': {
            'downstairs' : 'living',
            'jump' : 'garden'
        },
        'people' : [],
        'capacity' : 1
    }
}

We can count the occupants and capacity like this:

capacity = 0
occupancy = 0
for name, room in house.items():
    capacity+=room['capacity']
    occupancy+=len(room['people'])
print("House can fit", capacity, "people, and currently has:", occupancy, ".")

«  House can fit 7 people, and currently has: 2 .

Next: Experience - Exercise: Occupancy Dictionary