'How to get the desired output by adding N number multiplied by M times and so on in Python
Is there's a library to get the desired output with n number m times for example
selection_from = {'a':30.2,'b':21,'c':2.1, 'd':73.2}
desired_output = 98372
#get input >> user can select from selection_form
user_selection = ['a', 'c']
# get something which satisfy this equation
# m * selection_form['a'] + n * selection_form ['c'] <= desired_output
Result should be close to desired output
Solution 1:[1]
simple straight forward answer would be
selection_from = {'a':30.2,'b':21,'c':2.1, 'd':73.2}
desired_output = 98372
user_selection = ['a', 'c']
summ=0
for x in user_selection:
summ+= selection_from[x]
m=n=desired_output/summ
output:
(m,n)=(3045.572755417957, 3045.572755417957)
!this is possible solution if m and n can be rational if at all they need to be integers this wont be perfect fit as a solution
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
