for example def f(n):
and I wanna check whether the sum of the numbers within n
equal to 100 whether it is in 1s, 2s, 3,s 4s, 5s and so on, depending on the length of n
.
f(5050)
>>> True
This tests whether 5 + 0 + 5 + 0 == 100
and whether 50 + 50 ==100
and if any are true, it returns True
.
Whether it tests in 1s, 2s 3s 4s and so on, depends on the length of the number. For example a number with a length of 5 can only be tested in 1s.
f(12345)
>>> False
This tests whether 1 + 2 + 3 + 4 + 5 == 100
and only that.
If the length of n
was 15, it would test the digits in 1s, 3s and 5s.
and finally one more example:
f(25252525)
>>> True
This would test whether 2+5+2+5+2+5+2+5 == 100
and 25+25+25+25==100
and whether 2525+2525==100
So n
, which has a length of 8 would be tested in 1s , 2s , and 4s. It cannot be tested with 3s and 5s because the length of all the digits within the number being summed up must be the same.
I hope I was able to explain what I'm after. Usually I would post what I've tried but I have no idea how to iterate over the digits of a number in such a way