我想要的金額分配給運營商,但追加的循環後沒有跳轉到另一個變量:的Python跳轉到另一個變量列表後追加
op1 = []
op2 = []
op3 = []
operators = [op1, op2, op3]
unsigned_loans = [100, 200, 300, 400]
sum_of_all_loans = 0
for loan in unsigned_loans:
sum_of_all_loans += loan
per_user_amount = sum_of_all_loans/len(operators)
unsigned_loans.sort()
for oper in operators:
for loan in unsigned_loans:
print(loan)
if sum(oper) < per_user_amount:
oper.append(loan)
unsigned_loans.remove(loan)
print(oper)
輸出應該是:
op1=[100, 200] op2=[300] op3=[400]
但現在它顯示
op1=[100, 300] op2=[200] op3=[400]
請解釋你想要的分佈背後的邏輯。目前你剛剛提到了代碼,它是爲它寫的。我們如何猜測你想要的結果背後的邏輯? –