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.

ไทย

Digital root

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

ลูปสองตัวทำงานร่วมกันที่นี่ ลูปภายใน for จะบวกหลักเลขทั้งหมดครั้งเดียว; str(n) ทำให้คุณสามารถวนลูปผ่านหลักเลขเหล่านั้นในฐานะตัวอักษร ลูปภายนอก while จะทำซ้ำกระบวนการนี้จนกว่าจำนวนจะมีสองหลักหรือมากกว่า ซึ่งคือ enquanto n >= 10

Log in or create account · ⁨เข้าสู่ระบบหรือสร้างบัญชี⁩

IGCSE, A-Level & AP