+ 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.

1st May 2021, 1:45 AM
Emad
8 ответов
+ 2
Show your attempt.
1st May 2021, 2:32 AM
Dino Wun (Use the search bar plz!)
Dino Wun (Use the search bar plz!) - avatar
+ 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
1st May 2021, 4:05 PM
Hacker Badshah
Hacker Badshah - avatar
+ 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
2nd May 2021, 12:02 PM
Balázs Szabó
Balázs Szabó - avatar
+ 1
Can you comment the code
1st May 2021, 2:55 AM
Emad
+ 1
Do it on Code playground.
1st May 2021, 3:13 AM
Dino Wun (Use the search bar plz!)
Dino Wun (Use the search bar plz!) - avatar
+ 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 😊
1st May 2021, 6:14 AM
Hacker Badshah
Hacker Badshah - avatar
0
I dont know how to creat a logic
1st May 2021, 3:24 AM
Emad
0
How should i take different combinations
1st May 2021, 10:35 AM
Emad