From ec64dce3478ac84dc11fe9c9d3901f8fbffcd779 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Sat, 8 Jul 2023 14:12:25 +0200 Subject: [PATCH] int.sum_digits() --- requirements.txt | 1 + tools/tools.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 02300b0..2bd1a6d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ bs4~=0.0.1 beautifulsoup4==4.11.1 fishhook~=0.2.5 +pygame~=2.4.0 requests==2.28.1 setuptools==65.6.3 diff --git a/tools/tools.py b/tools/tools.py index 87ae83a..1108544 100644 --- a/tools/tools.py +++ b/tools/tools.py @@ -183,4 +183,15 @@ def intersection(self, *args) -> str: @hook(str) def __and__(self, *args) -> str: - return self.intersection(*args) \ No newline at end of file + return self.intersection(*args) + + +@hook(int) +def sum_digits(self) -> int: + s = 0 + num = self + while num > 0: + s += num % 10 + num //= 10 + + return s \ No newline at end of file