Ответ:
from itertools import combinations_with_replacement
def sumt(q, *tr):
result = []
for i in range(1, q + 1):
for j in combinations_with_replacement(list(tr), i):
if sum(list(j)) == q:
result.append(j)
return result[::-1]
n = int(input())
t = sumt(n, *range(1, n + 1))
for num in t:
a = list(map(str, num))
if len(a) == 1:
print(f'{"".join(a)} = {n}')
else:
a = ' + '.join(a)
print(f'{a} = {n}')
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Verified answer
Ответ:
from itertools import combinations_with_replacement
def sumt(q, *tr):
result = []
for i in range(1, q + 1):
for j in combinations_with_replacement(list(tr), i):
if sum(list(j)) == q:
result.append(j)
return result[::-1]
n = int(input())
t = sumt(n, *range(1, n + 1))
for num in t:
a = list(map(str, num))
if len(a) == 1:
print(f'{"".join(a)} = {n}')
else:
a = ' + '.join(a)
print(f'{a} = {n}')