Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def baseconvert(num, base):
- '''converts an integer "num" in base 10 to given base up to 36'''
- letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- result = ''
- if num == 0:
- return 0
- elif num < 0:
- isNeg = True
- else:
- isNeg = False
- while num > 0:
- if num % base <= 9:
- result = str(num % base) + result
- else:
- result = str(letters[(num % base) - 10]) + result
- num = num / base
- if isNeg:
- result = '-' + result
- return result
- number = int(raw_input('Enter a number: '))
- base = int(raw_input('Enter the base: '))
- print baseconvert(number, base)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement