← Back to challenges

Complete the Binary Number

PythonHardlanguage_fundamentalsstringsformatting

Instructions

Create a function which adds zeros to the start of a binary string, so that its length is a multiple of 8.

Examples

complete_binary("1100") ➞ "00001100"

complete_binary("1101100") ➞ "01101100"

complete_binary("110010100010") ➞ "0000110010100010"

Notes

Return the same string if its length is already a multiple of 8.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Are Letters in the Second String Present in the First?