python - 计数器 - 跳过元素并且在 for 循环期间不增加
问题描述
所以我正在为我的班级编写一个基本的登录系统,并且我正在使用 for 循环和计数器来线性搜索列表。但是,当我输入一个应该正确的用户名时,它返回为未经授权的。我已经尝试在循环的每次传递之间打印计数器,我发现即使范围是(0,6)它最多只能计数三个?
import random
userver = 0
userList = ["Arabella12", "Constance01", "Hugo11", "James09", "Jane12", "Max06", "Ted04"]
pwrdList = ["bella12", "1234", "HGWel!", "j@me£S", "Password", "notpassword", "ted4"]
found = False
pfound = False
def login():
username = input("Type in your username ")
index1 = 0
wrong = 0
found = False
c3 = 0
print("index one before c3 loop=", index1) #delete after testing
for c3 in range(0, 6): #username check counter
if username == userList[c3]: #if username is found with the counter c3
found = True #making the key for the next part of the code true
index = s(c3)
print(index," is the index")
c3 = c3 + 1
break
elif found == False:
print("c3: ", c3) #checking counter- delete after debugging
print("unauthorised user...attempting again") #if username isnt present
c3 = c3 + 1 #upping the counter
exit
login()
解决方案
推荐阅读
- python - 为什么我在创建 pygame 时收到错误“ValueError: list.remove(x): x not in list”?
- java - 将整个列表显示到可扩展列表视图中
- mulesoft - 在 Mulesoft Anypoint 平台 cloudhub 中获取 vpcID 和专用 loadbalancerID
- ruby-on-rails - 防止音译替换未知字符
- json - 如何使用 Spring-Webflux 将 JSON 发送到 PUT 端点
- javascript - Javascript D3 行生成器为 HTML 中的每个数据点生成 1 行
- jquery - [0].click() 触发一次, .click() 触发三次
- mongodb - 如何对字典键进行排序并在 MongoDb 中选择第一个?
- javascript - 等级系统实时数据库
- azure - 在 SSIS 中使用 Azure Blob 源从 Azure 存储容器中提取文件时出现“Azure Blob 源 400 错误请求”