[Python] Transferring items from one dictionary to another

Discussão em 'Python' iniciado por Stack, Abril 17, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on a college assignment and need to figure out how to transfer an item from one dictionary (item) to another (inventory). This needs to be done by finding an item in a room, using the search_for_items function. Here's the code I have thus far:

    rooms = {
    'Main Entry': {'East': 'Main Floor'},
    'Main Floor': {'North': 'North Hall', 'South': 'South Hall', 'East': 'Clothes Store', 'West': 'Main Entry'},
    'South Hall': {'East': 'Food Court', 'North': 'Main Floor'},
    'North Hall': {'East': 'Storage Room', 'South': 'Main Floor'},
    'Clothes Store': {'North': 'Theater', 'West': 'Main Floor'},
    'Theater': {'South': 'Clothes Store'}
    }

    item = {
    'Gas Mask',
    'Stuffed Shark',
    'Bubble Wrap',
    'Knowledge of Toaster Store',
    'Block of Old Cheese',
    'Baseball Bat'
    }

    has_item = {
    'Main Floor': {'Gas Mask'},
    'North Hall': {'Stuffed Shark'},
    'Storage Room': {'Bubble Wrap'},
    'South Hall': {'Knowledge of Toaster Store'},
    'Food Court': {'Block of Old Cheese'},
    'Clothes Store': {'Baseball Bat'}
    }

    inventory = {

    }

    def search_for_items():
    if room has_item = true:
    add item to inventory
    print('Got item: {}'.format(item))
    has_item = false
    else:
    print('No items here')


    So, I need to figure out how to map each item to each room, and I need to find a way to have the search_for_items function transfer an item from the list of items to the player's inventory.

    Continue reading...

Compartilhe esta Página