Problem 193091 · easy · Phase 01 Prerequisites & Setup

Write It in Binary

functions · base conversion · strings

Write to_binary(n) that returns the binary representation of the non-negative integer n as a string, without using bin() or format().

Examples

Input:  n = 5
Output: "101"

Input:  n = 0
Output: "0"

Input:  n = 255
Output: "11111111"

Constraints

  • 0 <= n <= 2**60
  • No leading zeros (except for the single "0").

Goals

  • Convert with repeated division by 2
  • Build a string in the right order
  • Special-case zero
Starting Python…