def to_hex(n):if n < 0:return '-' + to_hex(abs(n))elif n < 16:return format(n, 'X')else:return to_hex(n // 16) + format(n % 16, 'X')
num = 255hex_num = to_hex(num)print(hex_num) # Output: FF
def to_hex(n):
if n < 0:
return '-' + to_hex(abs(n))
elif n < 16:
return format(n, 'X')
else:
return to_hex(n // 16) + format(n % 16, 'X')
num = 255
hex_num = to_hex(num)
print(hex_num) # Output: FF