← run

bcb-0021

1.000
6/6 tests· lib-knowledge

Proposed solution

```python
import psutil
import platform

def task_func():
    """
    Obtain system details, including operating system, architecture, and memory usage.
    
    This function gathers information about the system's operating system, architecture,
    and memory usage. It calculates the percentage of used memory  by comparing the total
    and currently used memory. The gathered details are then returned in a dictionary 
    format with specific keys for each piece of information.
    
    Returns:
    dict: A dictionary containing:
        - 'OS': Operating System name (e.g., 'Windows', 'Linux').
        - 'Architecture': System architecture (typically first item from platform.architecture(), e.g., '64bit').
        - 'Memory Usage': Formatted string representing the percentage of memory currently in use, 
                            calculated as (used memory / total memory) * 100.
  
    Requirements:
    - platform
    - psutil

    Examples:
    >>> system_info = task_func()
    >>> isinstance(system_info, dict)
    True
    >>> 'OS' in system_info
    True
    >>> 'Architecture' in system_info
    True
    >>> 'Memory Usage' in system_info
    True
    """
    # Get operating system name
    os_name = platform.system()
    
    # Get system architecture
    architecture = platform.architecture()[0]
    
    # Get memory usage information
    memory_info = psutil.virtual_memory()
    used_memory = memory_info.used
    total_memory = memory_info.total
    memory_percentage = (used_memory / total_memory) * 100
    
    # Format memory usage as string
    memory_usage = f"{memory_percentage:.2f}%"
    
    # Return dictionary with system information
    return {
        'OS': os_name,
        'Architecture': architecture,
        'Memory Usage': memory_usage
    }
```

Test output (stdout)

......                                                                   [100%]
6 passed in 0.04s
System prompt
You are an expert programmer. Solve the task exactly as specified. Output your solution as fenced code blocks using the required file name(s) and the exact function/type signatures requested. Prefer correctness; do not include prose outside code unless asked.