diff --git a/main.py b/main.py index 7f4f555..1a679d4 100644 --- a/main.py +++ b/main.py @@ -5,12 +5,26 @@ def to_binary(n: int)->str: - pass + answer = "" + while n: + answer =str( n % 2) + answer + n //= 2 + return answer + + + # Press the green button in the gutter to run the script. if __name__ == '__main__': - to_binary(12) + assert to_binary(5) == "101" + assert to_binary(1) == "1" + assert to_binary(8) == "1000" + assert to_binary(15) == "1111" + print(to_binary(5)) + print(to_binary(1)) + print(to_binary(8)) + print(to_binary(15)) # See PyCharm help at https://www.jetbrains.com/help/pycharm/