ข้ามไปยังเนื้อหา

Digital root

Digital root

คงเพิ่ม digit ต่อไปจนกว่าจะมี digit เดียวเหลืออยู่

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.

เข้าสู่ระบบหรือสร้างบัญชี

IGCSE, A-Level & AP