nq1s788

16 сумма цифр суммы цифр

Feb 2nd, 2026
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. #3929 https://kpolyakov.spb.ru/school/ege/gen.php?action=viewAllEgeNo&egeId=16&cat44=on&cat45=on&cat46=on&cat181=on
  2. def f(s):
  3.     answ = sum(map(int, s))
  4.     if answ < 10:
  5.         return answ
  6.     return f(str(answ))
  7.  
  8.  
  9. #еще один вариант -- нерекурсивный
  10. def f1(s):
  11.     cur = s
  12.     while len(cur) > 1:
  13.         cur = str(sum(map(int, cur)))
  14.     return cur
  15.  
  16.  
  17. answ = 0
  18. for x in range(10, 100):
  19.     answ += f(str(x))
  20. print(answ)
Advertisement
Add Comment
Please, Sign In to add comment