Home My space log
Language EN (English)

Write a number in binary

Python Advanced astronaut ages teen+

The problem

Write a function to_binary(n). It gives back the binary digits of a whole number n (0 or more) as text. Example: 5 becomes "101". Do not use the built-in bin() function.

You will practice: binary numbers, while loops, remainder (%) and whole-number division (//), building text

Mode

Press Tab to indent. Press Esc and then Tab to move on to the next button.

Your code runs in your browser. We do not receive it or save it. Python is downloaded from cdn.jsdelivr.net the first time you run it (about 10 MB).

Test results

      What your code printed