mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-06-18 03:49:22 -04:00
some new examples
This commit is contained in:
parent
5ed530430c
commit
b50dc5d69d
84 changed files with 130 additions and 82 deletions
|
@ -1,24 +0,0 @@
|
|||
#!/usr/bin/python3
|
||||
# mari von steinkirch @2013
|
||||
# steinkirch at gmail
|
||||
|
||||
def convert_from_decimal(number, base):
|
||||
''' convert any decimal number to another base. '''
|
||||
multiplier, result = 1, 0
|
||||
while number > 0:
|
||||
result += number%base*multiplier
|
||||
multiplier *= 10
|
||||
number = number//base
|
||||
return result
|
||||
|
||||
|
||||
def test_convert_from_decimal():
|
||||
number, base = 9, 2
|
||||
assert(convert_from_decimal(number, base) == 1001)
|
||||
print('Tests passed!')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_convert_from_decimal()
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue