當我使用if
語句時,我將如何循環下面的代碼,我一直收到錯誤。我試圖讓下面的號碼打印出來,511887和使用條件語句比較每4位二進制數,但我不斷收到一個錯誤:NameError: name 'bin_list' is not defined
爲什麼當我想要循環時出現錯誤
x=("bin_list")
y=("bin_list[SN_0]")
["0001"]
"0101"
"0001"
"0001"
"1000"
"1000"
"0111"
SN_bin_0 = bin_list[SN_1]
for x in range (0,7):
for index in range(len(L)):
print (y)
SN_bin_1 = bin_list[SN_5]
for x in range (1,7):
for index in range(len(L)):
print (y)
SN_bin_2 = bin_list[SN_1]
for x in range (2,7):
for index in range(len(L)):
print (y)
SN_bin_3 = bin_list[SN_1]
for x in range (3,7):
for index in range(len(L)):
print (y)
SN_bin_4 = bin_list[SN_8]
for x in range (4,7):
for index in range(len(L)):
print (y)
SN_bin_5 = bin_list[SN_8]
for x in range (5,7):
for index in range(len(L)):
print (y)
SN_bin_6 = bin_list[SN_7]
for x in range (6,7):
for index in range(len(L)):
print (y)
什麼是你得到的錯誤?它看起來像你的縮進全是古怪的。 – Will
SN_bin_0 = bin_list [SN_1] NameError:name'bin_list'沒有被定義,但我已經從代碼中定義了變量 –
,它看起來像你沒有定義'bin_list'。你正在定義'x'併爲其分配字符串''bin_list「'。看起來你正在用'y'做類似的事情。 – Will