Skip to content · ⁨コンテンツへスキップ⁩

Digital root

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 の間)、これを繰り返します。

Log in or create account · ⁨ログインまたはアカウント作成⁩

IGCSE, A-Level & AP