SWE(5186)이진수2

SWE 5186 이진수2

for rounds in range(int(input())):
    num = float(input())
    result = ''
    cnt = 0
    while True:
        next_num = num*2
        print("next_num: ", next_num)
        result += str(int(next_num))
        print("result:", result)
        num = next_num-int(next_num)
        print("num: ", num)
        cnt += 1
        if num == 0.0:
            break
        if cnt > 13:
            break
    if cnt > 13:
        print(f"#{rounds+1} overflow")
    else:
        print(f"#{rounds+1} {result}")


참고자료 [SWexperacademy]https://swexpertacademy.com [python_16진수_2진수]https://www.daleseo.com/python-int-bases/ [참고자료_해리의_데브로그]https://tothefullest08.github.io/algorithm/2019/07/21/1_5185_%EC%9D%B4%EC%A7%84%EC%88%98/

0%