akela43

toBase

Apr 12th, 2020
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. def tobase(num, base):
  2.     base_num = ""
  3.     if num < 0:
  4.         sign="-"
  5.         num = -num
  6.     else:
  7.         sign = ""
  8.     while num > 0:
  9.         d = int(num % base)
  10.         base_num += str(d) if d < 10 else chr(ord('A')+ d - 10)  
  11.         num //= base
  12.     base_num = sign+base_num[::-1]
  13.     return base_num
  14. num, base = input("Введите десятичное число и основание: ").split()
  15. print(tobase(int(num),int(base)))
Advertisement
Add Comment
Please, Sign In to add comment