我将这段代码作为一个Python文件运行,它将从内置的.py函数input中打开一个命令提示符。(这里没有太多的智慧...)如果我输入diagnose,按enter只有vav2_12会打印booya列表上的所有其他人都会打印not working
有人知道为什么吗?
#list of addresses of controllers
# format : key = name, v = (address, device_identifier) tuple
vavs = {'vav1_1': ('1701:1'),
'vav1_2': ('1701:2'),
'vav1_3': ('1701:3'),
'vav1_4': ('1701:4'),
'vav1_5': ('1701:5'),
'vav1_6': ('1701:6'),
'vav1_7': ('1701:7'),
'vav1_8': ('1701:8'),
'vav1_9': ('1701:9'),
'vav1_10': ('1701:10'),
'vav1_11': ('1701:11'),
'vav1_12': ('1701:12'),
'vav2_1': ('1701:13'),
'vav2_2': ('1701:14'),
'vav2_3': ('1701:15'),
'vav2_4': ('1701:16'),
'vav2_5': ('1701:17'),
'vav2_6': ('1701:18'),
'vav2_7': ('1701:19'),
'vav2_8': ('1701:20'),
'vav2_9': ('1701:21'),
'vav2_10': ('1701:22'),
'vav2_11': ('1701:23'),
'vav2_12': ('1701:24'),
}
#dict(TUPLE)[key]
d = dict(vavs)
while True:
answer = input('Available actions: check_temps or diagnose?')
if answer == 'check_temps':
print('Checking Some Temps ...')
if answer == 'diagnose':
#print list of controller addresses
for vav in vavs.items():
print(vav[0])
diagAnswer = input('Which VAV to check?')
if vav[0] == diagAnswer:
print('Booya')
else:
print('Not working')
else:
pass发布于 2019-10-22 05:15:51
因为VAV值是迭代之后来自vavs的最后一项。
我相信你的解决方案是这样的:
if diagAnswer in vavs.keys():
print('Booya')
else:
print('Not working')https://stackoverflow.com/questions/58494044
复制相似问题