Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. def convert_base(num, to_base=10, from_base=10):
  2.  
  3.     if isinstance(num, str):
  4.         n = int(num, from_base)
  5.     else:
  6.         n = int(num)
  7.  
  8.     alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  9.     if n < to_base:
  10.         return alphabet[n]
  11.     else:
  12.         return convert_base(n // to_base, to_base) + alphabet[n % to_base]
  13.  
  14. while True:
  15.     num = int(input('Число' + '\n'))
  16.     from_base = int(input('с основанием' + '\n'))
  17.     to_base = int(input('в основание' + '\n'))
  18.     print(convert_base(num, to_base, from_base))
  19.     if input('Продолжить? Y/N ').lower() == 'n':
  20.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement