摆脱了 while True: 循环,这导致代码重复 NameError 异常发生。
while True:
NameError
另外,移动输入 done 进入 try 块。否则,该输入将覆盖 done = "y" 声明中 except 块。
done
try
done = "y"
except
while x <= qubits: while done == "n": print("this is qubit #",x) fstgat = "target" print("first gate is target") if fstgat in singates: #checks if there is an error from mem1 being undefined (control/target out of order) try: qstat[x]=singates[fstgat](qstat[x]) done = input("Done with your qubit? y or n: ") except NameError: print("switching qubits - we'll come back to this one") #error here -> keeps saying "which gate is this target qubit for" done = "y" else: print("sorry, that functionality is not yet implemented, try custom gate") done ="y" x+=1 done = "n"