Digital root
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
This one builds on a lesson you haven't finished yet. Do that lesson first: · 이 과제는 아직 완료하지 않은 수업에 기반합니다. 먼저 해당 수업을 완료하세요:
Python Basics · Functions →
English
Digital root
Keep adding digits until a single digit remains.
Two loops work together here. The inner for adds up the digits once; str(n) lets you loop over them as characters. The outer while repeats that as long as the number still has two or more digits, which is while n >= 10.
한국어
디지털 루트
한 자리 숫자가 남을 때까지 숫자를 계속 더하십시오.
여기서 두 개의 루프가 함께 작동합니다. 내부 for은 숫자를 한 번 더하고; str(n)은 이를 문자열로 순회하게 해줍니다. 외부 while은 숫자가 두 자리 이상일 동안(즉, n >= 10일 때) 그것을 반복합니다.
Write digital_root(n) that adds up the digits of n, then the digits of that answer, and so on until one digit is left. 9875 gives 29, then 11, then 2.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.