Nous dirons qu'un nombre n est positif n est parent du nombre à 2 chiffres ab
si son chiffre des unités est b et si ses autres chiffres sont différents de 0 et que leur somme est a.
Par exemple, les parents de 31 sont 31, 121, 211 et 1111
We say that a number n is parent of the number ab if it ones digit is equal to b and if he hasn't any digits equal to 0 and finally, if the sum of the digits of n is equal to a+b.
For example
121 is parent of 31 because :
1 = 1, 0 isn't in 1,2 and because 1 + 2 + 1 = 4 = 3 +1.
What you need to do
Complete the parents_of(n:int)
function so that she return every parents of n between 1 and 1000.
def parents_of(n:int):
toTest=[i for i in range(11,1000) if not "0" in str(i)]
dics={str(i):[] for i in toTest}
for nb in toTest:
for i in range(11,1000):
if str(i)[-1]==str(nb)[-1]: #Si ils ont le même chiffre des unités
if not "0" in str(i)[:-1]: #Si ils n'ont pas de 0
if sum([int(e) for e in str(i)])==sum([int(e) for e in str(nb)]): #Si ils ont la même some
dics[str(nb)]+=[i]
return dics[str(n)]
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("parents_of 31")
def thirty_one():
test.assert_equals(parents_of(31), [31, 121, 211])
@test.it("parents of 98")
def ninty_eight():
test.assert_equals(parents_of(99),[99, 189, 279, 369, 459, 549, 639, 729, 819])