Last active
August 29, 2015 14:11
-
-
Save fabian57/579c015244019ff7bd1c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_halves(n): | |
print n | |
while n > 0: | |
n = n / 2 | |
print n | |
print_halves(57) | |
def binary_length(n): | |
i = 0 | |
while n > 0: | |
n = n / 2 | |
i += 1 | |
return i | |
binary_length(57) | |
def binary_list(n): | |
acc = [] | |
while n > 0: | |
acc += [n % 2] | |
n = n / 2 | |
return acc | |
binary_list(57) | |
def binary_string(n): | |
acc = "" | |
while n > 0: | |
acc = str(n % 2) + acc | |
n = n / 2 | |
return acc | |
binary_string(57) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Parfait, a ceci près que les trois dernières devraient être des fonctions sans effet de bord (remplace
print
parreturn
).