【发布时间】:2019-04-15 21:34:13
【问题描述】:
此代码功能齐全,无需使用错误处理。有没有更有效的方法来写这个?我很想向大家学习。
from getpass import getpass
username = input("Username: ")
grant_access = False
while not grant_access:
password = getpass("Password: ")
if password == 'pass123':
grant_access = True
elif password != 'pass123':
while not grant_access:
password = getpass("Re-enter Password: ")
if password == 'pass123':
grant_access = True
elif password != 'pass123':
continue
print("Logging in...")
【问题讨论】:
-
这个问题在Code Review 上可能会更好。
标签: python python-3.x loops