有时,我必须在控制台中引入两次输入,以使我的while循环能够识别它。代码真的很简单,我似乎找不到发生这种情况的原因。
我尝试过更改语法,并修改了while循环,但是结构仍然如此简单,不应失败。每次我遇到相同的错误,即使控制台无法识别它。
note_dict = {
"F2": 1,
"F#2": 2,
"Gb2": 2,
"G2": 3,
"G#2": 4,
"Ab2": 4,
"A2": 5,
"A#2": 6,
"Bb2": 6,
"B2": 7,
"C3": 8
}
bases = []
print("Introduce your inputs: (Write exit to finish) \n")
while True:
base = input("")
if base == "exit":
break
if base in note_dict:
bases.append(note_dict[base])
continue
else:
print("Not recognized")
continue
print(bases)
预期是这样的(在控制台中):
Introduce your inputs: (Write exit to finish)
Bb2
B2
C3
C4
Not recognized
exit
[6, 7, 8]
我通常(在控制台中)得到的东西:
Introduce your inputs: (Write exit to finish)
Bb2
B2
C3
C4
C4
Not recognized <- Had to write it twice to say that
exit
exit <- Again, it didn't recognize it until the second time
[6, 8] <- The results aren't even right...