Hw

PHOTO EMBED

Wed Nov 27 2024 02:27:52 GMT+0000 (Coordinated Universal Time)

Saved by @sk #python

n = input("Введите число с периодом (например, 0.1(23)): ")

f_index = n.index('(')
period = n[f_index + 1:n.index(')')]
non_periodic = n[:f_index]

a = non_periodic.replace('.', '') + period

integer_part = int(non_periodic.replace('.', '')) if '.' in non_periodic else int(non_periodic)

non_periodic_length = len(non_periodic.split('.')[-1]) if '.' in non_periodic else 0
period_length = len(period)

numerator = integer_part * (10 ** (non_periodic_length + period_length) - 1) + int(period)
denominator = (10 ** non_periodic_length - 1) * (10 ** period_length)

def to_base_6(value):
    if value == 0:
        return '0'
    base_6_value = ''
    while value > 0:
        base_6_value = str(value % 6) + base_6_value
        value //= 6
    return base_6_value

base_6_numerator = to_base_6(numerator)
base_6_denominator = to_base_6(denominator)

print(f'Число в шестиричной системе: {base_6_numerator}/{base_6_denominator}')
content_copyCOPY