Python 密码中的一个特殊字符
我有一个小问题,因为我想检查用户密码并强制必须使用一个特殊字符。但在我的输出中,即使创建了密码,我也会收到无效消息。我该如何修复这个东西?
special_character= '$#!'
created = False
while not created:
password = input('Type your password: ')
for char in special_character:
if char in password:
print('Password Created!!')
created = True
else:
print('Sorry, try again!')
Output:
Type your password: MyStronPassword123$
Password Created!!
Sorry, try again!
我怎样才能丢弃这个文本:“抱歉,再试一次”
I have a tiny problem, because i want to check user password and force so that must using one special character. But in my output i get a invalid message even though password is created. How can i repair this thing?
special_character= '$#!'
created = False
while not created:
password = input('Type your password: ')
for char in special_character:
if char in password:
print('Password Created!!')
created = True
else:
print('Sorry, try again!')
Output:
Type your password: MyStronPassword123$
Password Created!!
Sorry, try again!
How can i discard this text: "Sorry try: again"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该使用if语句查看是否创建了密码。
输出:
输入密码:Mystronpassword123 $
密码创建!
You should use an if statement to see if the password is created.
Output:
Type your password: MyStronPassword123$
Password Created!!
尝试使用以下方法:
Try using the following method:
您的
else
语句将始终被执行,我想您希望仅当 for 循环被中断时才执行它,在这种情况下添加break
:Your
else
statement will always be executed, I suppose you want it to be executed only if the for loop is interrupted in that case addbreak
: