Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # fracbase.py
- import sys, math
- target = float(sys.argv[1])
- base = float(sys.argv[2])
- def decomp(tarnum, nbase):
- if nbase <= 1:
- return 'ERROR Base must be > 1'
- print('nRepresenting', tarnum, 'in base', nbase, ' Log is', math.log(tarnum, nbase), 'n')
- powr = int(math.log(tarnum, nbase))
- rep = []
- while powr > -13:
- tnratio = tarnum / nbase**powr
- rep.append(int(tnratio))
- print('There are', tnratio, nbase, 'to the power of', powr, 'in', tarnum, 'so', rep)
- tarnum -= int(tnratio) * nbase**powr
- if tarnum == 0:
- if powr > 0:
- for i in range(powr):
- rep.append(0)
- return rep
- if powr == 0:
- rep.append('.')
- powr -= 1
- return rep
- print(decomp(target, base))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement