arrow

def decimal_to_binary(n): return bin(n).replace("0b", "") def decimal_to_hex(n): return hex(n).replace("0x", "").upper() def convert(): input_string = Element('input-number').element.value input_base = Element('input-base').element.value output_base = Element('output-base').element.value input_base = int(input_base) Element('error').write('') output_number = '' if input_string: try: decimal_number = int(input_string, input_base) match output_base: case '2': output_number = decimal_to_binary(decimal_number) case '10': output_number = decimal_number case '16': output_number = decimal_to_hex(decimal_number) case _: output_number = '' except Exception as e: Element('error').write(e) Element('output-number').element.value = output_number