TypeError:索引列表必须是整数,而不是s

2024-09-22 16:28:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码中有什么地方出错了: TypeError:索引列表必须是整数,而不是str

这是我的代码:

print("This programe will keep track of your TV schedule.")
Finish = False
Show = []
ShowStart = []
ShowEnd = []
while not Finish:
print()
ShowName = input("What is the shows name?: ")
if ShowName == "":
    Finish = True
else:
    ShowStartTime = input("What time does the show start?: ")
    ShowEndTime = input("What time does the show end?: ")
    Show.append(ShowName)
    ShowStart.append(ShowStartTime)
    ShowEnd.append(ShowEndTime)
print("{0:<10}  |  {1:<10}  |  {2:<10}  ".format("Show Name", "Start Time", "End Time"))
for each in Show:
print("{0:<10}  |  {1:<10}  |  {2:<10}  ".format(Show[each], ShowStart[each],  ShowEnd[each]))
input()

Tags: the代码inputtimeshowwhateachprint
1条回答
网友
1楼 · 发布于 2024-09-22 16:28:32

你的最后一个循环是错误的。试试这个:

for each in range(len(Show)):
    print("{0:<10}  |  {1:<10}  |  {2:<10}  ".format(Show[each], ShowStart[each],  ShowEnd[each]))

(您的3个列表应该通过以下方式合并到一个字典列表中:

^{pr2}$

相关问题 更多 >