def parents_of(n:int): if len(str(n)) != 2: return [] toTest = [i for i in range(11, 1000) if not "0" in str(i)] answer = [] for nb in toTest: if str(n)[-1] == str(nb)[-1]: if sum([int(e) for e in str(n)]) == sum([int(e) for e in str(nb)]): answer.append(nb) return answer
- 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}- if len(str(n)) != 2:
- return []
- toTest = [i for i in range(11, 1000) if not "0" in str(i)]
- answer = []
- 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ésif not "0" in str(i)[:-1]: #Si ils n'ont pas de 0if sum([int(e) for e in str(i)])==sum([int(e) for e in str(nb)]): #Si ils ont la même somedics[str(nb)]+=[i]return dics[str(n)]- if str(n)[-1] == str(nb)[-1]:
- if sum([int(e) for e in str(n)]) == sum([int(e) for e in str(nb)]):
- answer.append(nb)
- return answer
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 99") def ninety_nine(): test.assert_equals(parents_of(99), [99, 189, 279, 369, 459, 549, 639, 729, 819])
- 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")- @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])- @test.it("parents of 99")
- def ninety_nine():
- test.assert_equals(parents_of(99), [99, 189, 279, 369, 459, 549, 639, 729, 819])