Digital root · รากดิจิทัล
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
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. · เขียน digital_root(n) ที่บวกหลักตัวเลขของ n, จากนั้นบวกหลักตัวเลขของคำตอบที่ได้, และทำเช่นนี้ต่อไปจนเหลือเพียงหลักเดียว. 9875 ให้ผลลัพธ์ 29, ต่อด้วย 11, แล้ว 2.
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่