secound
This commit is contained in:
parent
fb5673b2a5
commit
e2703f522f
18
main.py
18
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/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user