<pre><code>def printsection1(animals, station1, station2):
animals=['a01', 'a02', 'a03', 'a04', 'a05']
station1={'a04': 5, 'a05': 1, 'a03': 6, 'a01': 2}
station2={'a04': 5, 'a02': 3, 'a03': 4, 'a01': 1}
print('Number of times each animal visited each station :')
print('Animal Id'+' '*11+'Station 1'+' '*11+'Station 2'+' ')
#preparing animal station1 and station2
for name in animals:
if name in station1:
visit=str(station1.get(name))
else:
visit=0
if name in station2:
visit2=str(station2.get(name))
else:
visit2=0
space=str((20-len(visit))*' ')
print(name+' '*17+str(visit)+space+str(visit2))
print('='*60)
</code></pre>
<p>实际输出,我得到的输出:</p>
<pre><code>Animal Id Station 1 Station 2
a01 2 1
</code></pre>
<p>错误:</p>
<pre><code>builtins.TypeError: object of type 'int' has no len()
</code></pre>
<p>所需输出:</p>
<pre><code>Number of times each animal visited each station :
Animal Id Station 1 Station 2
a01 2 1
a02 0 3
a03 6 4
a04 5 5
a05 1 0
============================================================
</code></pre>
<p>嘿,伙计们,我本来在做这个节目,但现在卡住了。我正在打印动物的身份证和两个电台。这三个电台都有20个字符长,但我总是因为某些原因而出现这个错误。</p>
<p>希望你们能帮忙:)</p>
<p>谢谢</p>