下面是一段代碼,從我的項目軟件:Python的多重嵌套,而真正的繼續/結束循環錯誤
def fun_1(self, i):
print("")
print("Welcome to Option 1: View Passwords")
while True:
print("")
which_o1 = input("1: Input a New Account details \n2: Exit \nPlease Input the option number: ")
if which_o1 == str(1):
with open(str(i)+'.txt', 'a+') as file:
while True:
print("")
web_n = input("Please Input Website name: ")
print("")
e_u = input("Please input email/username: ")
print("")
pass_w = input("Please input password: ")
while True:
print("")
sure = input("Website- " +web_n+"\nEmail/Username- "+e_u+"\nPassword- "+pass_w+"\nAre You sure about these details? Yes/No: ")
if (sure.lower()[0]) != 'y' and (sure.lower()[0]) != 'n':
print("")
print("Please input a valid response Yes/No!")
continue
elif (sure.lower()[0]) == 'y' and (sure.lower()[0]) != 'n':
list_log = [web_n, e_u, pass_w]
file.write(str(list_log) + '\n')
break
break
continue
elif (sure.lower()[0]) == 'n' and (sure.lower()[0]) != 'y':
break
continue
elif which_o1 == str(2):
return (i)
else:
print("")
print("Please Enter a Valid Response!")
continue
所以有您可以看到,它有3個,而真正的循環。問題發生時打破和循環循環。如果你在中間elif的「pass_w」下看到最新的While True,它說elif (sure.lower()[0]) == 'y' and (sure.lower()[0]) != 'n':
,在這裏我有2個break和1,因爲我想要做的是,當elif執行它時,第二,true和continue意味着循環第一次,而在代碼開始時爲true,但它只是在代碼的中間繼續循環第三行,而不是破壞它。
有沒有辦法讓我可以做到這一點?
休息,並繼續不工作的方式,你不能堆疊在一起。 –