gpt4 book ai didi

python - 坚持我所做的这段代码

转载 作者:太空宇宙 更新时间:2023-11-03 17:21:44 24 4
gpt4 key购买 nike

如果您从我创建的列表中输入通用密码,则此代码应该显示“请输入新密码”,但事实并非如此,它只是显示“密码已接受”,但事实并非如此。有人可以帮我吗?这是代码本身:

### Asks user for their name and password ###

print "Hello, what is your name?"

### Stores name in variable myName ###

myName = raw_input()

print "Nice to meet you "+myName+", please enter a password to continue."

common_passwords = [ '123456', 'password', '12345', '12345678', 'qwerty',
'1234567890', 'baseball', 'dragon', 'football', '1234567',
'monkey', 'letmein', 'abc123', '111111', 'mustang', 'access',
'shadow', 'master', 'michael', 'superman', '696969', '123123',
'batman', 'trustno1']

while True:
password = raw_input()
if len(password) < 8:
print "Password is less than 8 characters."
print "Your password has to be 8 characters or more."
continue
found = False
for cpass in common_passwords:
if cpass == password:
print "You have selected a common password"
print "Please choose a new password"
found = True
break
if not found:
print "Password Accepted"
break

最佳答案

您想做的可能是:

for cpass in common_passwords:
if cpass == password:
print "You have selected a common password"
print "Please choose a new password"
found = True
break
if not found:
print "Password Accepted"

因为您想检查输入的密码是否在 common_password 中找到,如果循环之后没有找到,则密码没问题。

此外,您可以简单地使用以下命令检查密码是否存在:

If password in common_passwords:
print "You have selected a common password"
print "Please choose a new password"
else :
print "Password Accepted"

关于python - 坚持我所做的这段代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33068211/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com