boris-vlasenko

вещественное из 10 в p

Dec 4th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. n = float(input())
  2. p = int(input())
  3. a = n - int(n)
  4. n = int(n)
  5. res = ''
  6. while n >= p:
  7.         res = str(n % p) + res
  8.         n = n // p
  9. res = str(n) + res
  10. res += '.'
  11.  
  12. a = a - int(a)
  13. i = 0
  14. while i < 7 and a != 0:
  15.     a *= p
  16.     res += str((int(a)))
  17.     a = a - int(a)
  18.     i += 1
  19. print(res)
Advertisement
Add Comment
Please, Sign In to add comment