programmers | Lv1. 3진법 뒤집기 [Python]

yeonk·2022년 2월 12일
0

algorithm

목록 보기
16/88
post-thumbnail

💡 Python 3






🔗 문제

3진법 뒤집기 [Link]






💻 코드

def solution(n):
    result = ''
    while n > 0:
        n, mod = divmod(n, 3)
        result += str(mod)
    return int(result, 3)






💥 다른 사람 코드

divmod를 사용하지 않은 코드

def solution(n):
    tmp = ''
    while n:
        tmp += str(n % 3)
        n = n // 3

    answer = int(tmp, 3)
    return answer






참고 자료

파이썬 진수변환(2진법, 3진법, 5진법, 10진법)[n진법]

[Python] 진법 변환 총 정리?!

0개의 댓글