How do I return to the first line of code in a loop Python
本问题已经有最佳答案,请猛点这里访问。
我正在尝试编写一个简单的python代码块,我希望在将来的程序中重用它。 它将检查密码是否正确以及是否未返回到第一行代码并再次启动该过程。 我试图完成的方式给了我一个错误。 谁能帮我找到更好的解决方案? 这是我目前使用的代码:
1 2 3 4 5 6 7 8 9 10 11 12 | def password_checker(): program_acceptance ="Welcome to the Program! " acceptable_password ="Godisgood" print("Please Enter the Password") while True: password = input("Password: ") if password == acceptable_password: print(program_acceptance) break if password != acceptable_password: print("Invalid password, please try again..." break |
应该删除最后一个
1 2 3 4 5 6 7 8 9 10 11 12 13 | def password_checker(): program_acceptance ="Welcome to the Program! " acceptable_password ="Godisgood" print("Please Enter the Password") while True: password = input("Password: ") if password == acceptable_password: print(program_acceptance) break if password != acceptable_password: print("Invalid password, please try again...") password_checker() |