擅长:python、mysql、java
<p>为了使其更通用,一个接受标记类型元组的函数:</p>
<pre><code>def stamps(postage_cost,stamps):
stamps_required = []
for stamp in stamps:
(num_stamps,remainder) = divmod(postage_cost,stamp)
stamps_required.append(num_stamps)
postage_cost = remainder
return tuple(stamps_required)
stamp_types = (5,2,1)
required = stamps(8,stamp_types)
print(required)
</code></pre>