python - 有机会的记号
问题描述
我是 Python 新手,所以请帮忙。如果密码错误,我希望它减少机会。如果我输入错误的密码,它会卡在 2
while True:
password = input("Password for activation ")
chance = 3
if password == "LUN":
print("access granted")
break
if password != "LUN":
wrong = chance - 1
print("Try again. your chance is {0}".format(wrong))
if chance == 0:
break
解决方案
你有chance = 3
你的while循环。所以每个循环,机会都会回到 3。
推荐阅读
- python - ImportError:没有名为 nocaptcha_recaptcha 的模块,但已安装
- java - Spring Boot:发布到 REST API 将单个字符串存储为数组
- firebase - Firebase FCM 实例 ID 服务器返回 401/403 错误代码
- javascript - 如何根据属性正确处理订阅
- android - 滚动时在回收站视图中保存 SwitchCompat 状态
- javascript - AJAX 不执行 php 脚本
- apache-spark - 使用 Psycopg2 将 Spark DataFrame 写入 Redshift 时出错:无法腌制 psycopg2.extensions.cursor 对象
- python - python对称加密到二进制没有时间戳
- javascript - 自定义确认功能
- javascript - How to export multiple class methods