我正在尝试编写一个简单的python代码块,我想在将来的程序中重用它。它将检查密码是否正确,以及是否返回到第一行代码,然后重新启动该过程。我试图完成的方式给了我一个错误。有人能帮我找到更好的解决方案吗??以下是我当前使用的代码:
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
最后一条
break
语句应该被删除,以确保程序在提供假密码时继续循环。在相关问题 更多 >
编程相关推荐