+ 1
I am looking for a function that find A numbers in B range that sum to C Ex: B =5 A =3 C= 8 Output: 1 2 5 1 3 4
Please comment the code im stuck, dont know how to creat the logic.
8 Antworten
+ 2
Show your attempt.
+ 2
Emad by using combinations function of itertools module
For instance
from itertools import combinations
arr = [1,2,3,4]
print(combinations(arr , 2)
This code will print all combinations of this list of length 2
+ 2
Hey, I've written some code that could be a good start to solving your problem, check it out:
https://code.sololearn.com/cUO6Y7BjeAzO/?ref=app
+ 1
Can you comment the code
+ 1
Do it on Code playground.
+ 1
Just take out different combinations of number in range of B of length A
And print them if their sum equals C
You can use combinations function of itertools module
Hope It Helps You 😊
0
I dont know how to creat a logic
0
How should i take different combinations