如何返回循环Python中的第一行代码

时间:2017-07-13 21:41:57

标签: python

我正在尝试编写一个简单的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

1 个答案:

答案 0 :(得分:1)

应删除最后一个encrypted_db_password = os.environ['db_password'] try: print 'attempting to decrypt' db_password = boto3.client('kms').decrypt(CiphertextBlob=b64decode(encrypted_db_password)['Plaintext'] print 'successfully decrypted' except: print "Error decrypting, assuming a local environment" db_password = encrypted_db_password 语句,以确保程序在提供虚假密码时保持循环。

break