Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def convert_base(num, to_base=10, from_base=10):
- if isinstance(num, str):
- n = int(num, from_base)
- else:
- n = int(num)
- alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- if n < to_base:
- return alphabet[n]
- else:
- return convert_base(n // to_base, to_base) + alphabet[n % to_base]
- while True:
- num = int(input('Число' + '\n'))
- from_base = int(input('с основанием' + '\n'))
- to_base = int(input('в основание' + '\n'))
- print(convert_base(num, to_base, from_base))
- if input('Продолжить? Y/N ').lower() == 'n':
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement