【发布时间】:2021-02-22 16:28:52
【问题描述】:
这是我的源代码:
destinations={"",}
destinations.discard("")
flightterminals={"Terminal 1":[],"Terminal 2":[], "Terminal 3":[]}
proceed="yes"
count=0
flightnumber=int(input("How many flights do you want to add: "))
for i in range(flightnumber):
count+=1
print("Where is plane {} headed?".format(count))
temp=input("")+"1"
destinations.add(temp[:-1])
while ((temp in flightterminals["Terminal 1"]) or (temp in flightterminals["Terminal 2"]) or (temp in flightterminals["Terminal 3"])):
temp=temp[:-1]+str(int(temp[-1])+1)
print(type(temp))
print(temp)
flightterminals["Terminal {}".format((count-1)%3+1)]+=temp
print(flightterminals["Terminal 1"])
这是终端:
Flight Terminal Manager 5600
How many flights do you want to add: 1
Where is plane 1 headed?
x
<class 'str'>
x1
['x', '1']
倒数第三行 flightterminals["Terminal {}".format((count-1)%3+1)]+=temp 似乎将两个字符串添加到我的字典中的一个集合中,尽管 temp 在前一行中显示为只是一个字符串。我做错了什么?
【问题讨论】:
标签: string dictionary set