Python 기본 사항쉬움

10진수를 8진수로 변환

'십진수에서 8진수로 변환' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

음수가 아닌 정수 n을 취하고 이에 상응하는 8진수(base-8)를 나타내는 문자열을 반환하는 함수 decimal_to_octal(n)을 작성하세요. 선행 0을 포함하지 마십시오('0'을 반환해야 하는 입력 0 제외).

10진수를 8진수로 변환하려면 숫자를 8로 반복해서 나누고 나머지를 역순으로 모으십시오.

제약
  • 0 <= n <= 10^6

Example 1
Input
decimal_to_octal(100)
Output
'144'
Explanation

100 ÷ 8 = 12 remainder 4, 12 ÷ 8 = 1 remainder 4, 1 ÷ 8 = 0 remainder 1. Reading remainders bottom-up: 144.

Example 2
Input
decimal_to_octal(15)
Output
'17'
Explanation

15 ÷ 8 = 1 remainder 7, 1 ÷ 8 = 0 remainder 1. Result: 17.

Example 3
Input
decimal_to_octal(8)
Output
'10'
Explanation

8 ÷ 8 = 1 remainder 0, 1 ÷ 8 = 0 remainder 1. Result: 10.

Need a Hint?
세트나 힙과 같은 Numbers 관련 데이터 구조를 사용해 보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.