Complete the code to show how devices connect in a network.
devices = ['Computer', 'Phone', 'Printer'] network = [1](devices) print(network)
The list type is used here to group devices in a network because it keeps the order and allows duplicates, just like devices connected in a network.
Complete the code to send a message from one device to another.
def send_message(sender, receiver, message): print(f"{sender} sends to {receiver}: {message}") send_message('Phone', 'Computer', [1])
The message must be a string, so it needs quotes like 'Hello!'.
Fix the error in the code that simulates devices communicating in a network.
network = {'Computer': 'Online', 'Phone': 'Offline'}
status = network.get([1])
print(status)The key must be a string matching the dictionary keys, so it needs quotes like 'Phone'.
Fill both blanks to create a dictionary showing device statuses and check if a device is online.
devices_status = [1](Computer='Online', Phone='Offline') if devices_status.get('Computer') == [2]: print('Computer is connected')
dict creates the dictionary. The status to check is the string 'Online'.
Fill all three blanks to create a dictionary comprehension that maps devices to their status if they are online.
devices = ['Computer', 'Phone', 'Printer'] statuses = {'Computer': 'Online', 'Phone': 'Offline', 'Printer': 'Online'} online_devices = { [1]: [2] for [3] in devices if statuses[[3]] == 'Online' }
The comprehension uses device as the key and statuses[device] as the value. The loop variable is also device.