我正在编写一个python"脚本"从Octal转到Binary现在我遇到了这个:
OctalBinary1 = {
"0" : "000",
"1" : "001",
"2" : "010",
"3" : "011",
"4" : "100",
"5" : "101",
"6" : "110",
"7" : "111"
}
def toBinaryOctal(x):
counter = 0
sum_var = ""
fin_var = ""
if len(x) % 3 == 0:
for i in x:
counter += 1
sum_var += str(i)
if counter == 1:
for x , y in OctalBinary1():
if x == sum_var:
print ("ok")
fin_var += OctalBinary1[x]
toBinaryOctal("123")
这是我的剧本:
Led1 = new wxLed(Panel1,ID_LED1,wxColour(0,0,0),wxColour(0,255,0),
wxDefaultPosition,wxDefaultSize);
答案 0 :(得分:2)
迭代dict的键和值的正确方法是:
for x, y in OctalBinary1.items():
if x == sum_var:
print ("ok")
fin_var += OctalBinary1[x]