Complete the code to print the number of CPU cores available on the system.
import os cores = os.cpu_count() print('CPU cores:', [1])
The variable cores stores the number of CPU cores returned by os.cpu_count(). We print this variable to show the count.
Complete the code to calculate the total memory in bytes using the given hardware info dictionary.
hardware_info = {'memory_gb': 8}
total_bytes = hardware_info['memory_gb'] * [1]
print('Total memory in bytes:', total_bytes)1 GB equals 1024³ bytes (1024 * 1024 * 1024). Multiplying memory in GB by this converts it to bytes.
Fix the error in the code to correctly calculate the CPU speed in MHz from GHz.
cpu_speed_ghz = 3.5 cpu_speed_mhz = cpu_speed_ghz [1] 1000 print('CPU speed in MHz:', cpu_speed_mhz)
To convert GHz to MHz, multiply by 1000 because 1 GHz = 1000 MHz.
Fill both blanks to create a dictionary comprehension that maps each device name to its RAM size in MB.
devices = {'laptop': 8, 'tablet': 4, 'phone': 2}
ram_mb = { [1]: [2] * 1024 for [1] in devices }The comprehension iterates over device names as device. For each, it maps the device name to its RAM in MB by multiplying the GB value by 1024.
Fill all three blanks to create a dictionary comprehension that includes only devices with RAM greater than 3 GB, converting RAM to MB.
devices = {'laptop': 8, 'tablet': 4, 'phone': 2}
filtered_ram = { [1]: devices[[2]] * 1024 for [3] in devices if devices[[2]] > 3 }The comprehension uses name as the loop variable and key. It filters devices with RAM > 3 GB and converts RAM to MB.