[英]Add space between each character after it is multiplied n times in python
[英]How to get the desired output by adding N number multiplied by M times and so on in Python
是否有一個庫來獲得所需的 output 例如n
次m
次
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
結果應該接近所需的 output
簡單直接的答案是
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)
!這是可能的解決方案,如果 m 和 n 可以是合理的,如果它們需要是整數,這將不是完美的解決方案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.