https://www.codetree.ai/training-field/home/relay/problems/base-conversion-7/description
코드트리 | 코딩테스트 준비를 위한 알고리즘 정석
국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요.
www.codetree.ai
s = float(input())
integer_part = int(s)
fractional_part = s - int(s)
def binary_integer(n):
result = ''
while n:
result = str(n % 2) + result
n //= 2
return result
def binary_fractional(n):
result = ''
while n!=0:
n *= 2
result += str(int(n))
n -= int(n)
return result
print(binary_integer(integer_part) + "." + binary_fractional(fractional_part)[:4])
728x90
반응형
'🔻PS > Codetree' 카테고리의 다른 글
[Codetree] 뿌요뿌요 Python (0) | 2024.07.19 |
---|---|
[Codetree] 안전 지대 Python (0) | 2024.07.19 |
[Codetree] 마을 구분하기 Python (0) | 2024.07.19 |
[Codetree] 두 방향 탈출 가능 여부 판별하기 Python (0) | 2024.07.19 |
[Codetree] 그래프 탐색 Python (0) | 2024.07.19 |