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)
實際輸出,輸出我得到:builtins.TypeError:類型 'INT' 對象沒有LEN()
Animal Id Station 1 Station 2
a01 2 1
錯誤:
builtins.TypeError: object of type 'int' has no len()
求購輸出:
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
============================================================
嘿傢伙我正在做這個程序,但我堅持在這一點上。我正在嘗試打印動物身份證和兩個站。所有三個站的長度都是20個字符,但由於某些原因,我一直收到此錯誤。
希望你們能幫助:)
感謝