Loading...
Loading...
Loading...
A computer stores numbers in binary, using only the digits 0 and 1. To convert a number to binary, divide it by 2 again and again and write down the remainders; read them from last to first.
Given n, print its binary form without using any built-in conversion.
Example
Input
10
Output
1010
10 is 1010 in binary.
Try the problem first. Open one hint at a time.
Each division by 2 gives a remainder (n % 2) that is the next digit from the right.
Because digits come out right to left, put each new digit in front of the text you have so far. Handle 0 separately.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor