Posts: 26
Threads: 1
Joined: Mar 2022
(Apr-27-2022, 12:16 PM)Dexty Wrote: (Apr-27-2022, 05:10 AM)sunny9495 Wrote: How to split a number to list and list sum must be number
Example :
x = 8
i want to split and make a list with 3 items and the sum of list must be equal to x
y = [3, 3, 2]
Any help is appreciated
You should consider what @ibreeden has said. I tried something out though. You might want to check it out and how it works:
for i in range(x):
for j in range(x):
for k in range(x):
if i + j + k == x:
print([i, j, k])
...where x=8
Hello,
for i in range(10):
for j in range(10):
for k in range(10):
if i + j + k == 15:
print(f"{i*100 + j*10 + k} ----> {i} + {j} + {k} =15")
import itertools
for i, j, k in itertools.product(range(10), range(10), range(10)):
if i + j + k == 15:
print(f"{i*100 + j*10 + k} ---->{i} + {j} + {k} =15")
I speak Python but I don't speak English (I just read it a little). If I express myself badly, please blame the translator^^.