Prompt
Write a Python function `format_bytes(n)` that formats a non-negative integer byte count as a
human-readable string using binary units (1 unit = 1024 of the previous): B, KB, MB, GB, TB, PB.
- Below 1024 bytes: `"<n> B"` (no decimals), e.g. `format_bytes(500) == "500 B"`.
- Otherwise one decimal place and the largest unit that keeps the value below 1024, e.g.
`format_bytes(1536) == "1.5 KB"`, `format_bytes(1048576) == "1.0 MB"`.
Put it in a single Python code block. It will be imported as `from solution import format_bytes`.when to use it
Community prompt sourced from the open-source GitHub repo Green-PT/honey-for-devs (MIT). A "Prompt" style prompt — adapt the placeholders and specifics to your task. Imported as-is and not independently retested here, so check the output before relying on it.
tags
codingcommunitydeveloper
source
Green-PT/honey-for-devs · MIT
more in Coding
Coding✓ tested
Senior code review (strict mode)
senior staff engineer running a merciless but fair review
Coding✓ tested
Debug by hypothesis, not by guessing
debugging partner who forms theories before touching code
Coding✓ tested
Generate tests from described behavior
test engineer who writes tests that would actually catch regressions