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.
日本語
デジタルルート
桁の和を繰り返し加え、単一の桁になるまで続けます。
ここで2つのループが連携します。内側のfor は一度だけ桁の和を計算し、str(n) は文字としてループ可能にします。外側のwhile は、数字が2桁以上ある間(つまり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. · 実行ボタンをクリックして出力を確認してください。