擅长:python、mysql、java
<p>这就是我的结局。谢谢你们的帮助,伙计们!你知道吗</p>
<pre><code>weights=[100, 45, 35, 25, 10, 5, 2.5]
target_weight = int(input('How much weight do you need? '))
bar_weight = int(input('Enter bar weight: '))
nweights = []
remaining = target_weight - bar_weight
for i, weight in enumerate(weights):
if int(remaining / weight) % 2 == 0:
nweights.append(int(remaining/ weight))
else:
nweights.append(int(remaining/ weight) - 1)
remaining = remaining - nweights[i]*weights[i]
if remaining == 0:
break
listweights=zip(nweights, weights)
print(f'{bar_weight}lb bar')
for weight in listweights:
if weight[0] >= 2:
print(f"{weight[0]} | {weight[1]}'s")
if remaining !=0:
print(f'the correct weight combination cannot be found,'
f'the remaining weight is: {remaining} pound')
</code></pre>