让我们一步一步来:
首先,检查用户是否存在将始终告诉您它是否存在,因为您正在添加用户,然后检查用户是否存在。所以你写的if语句是可以的,但是把它放在store_user.append之前:if user in store_user:
print "That user already exsist"
else:
store_user.append(user)
store_pass.append(password)
第二,你为while 1 == 1:写的条件是无用的(但仍然正确),你可以做while 1(因为1的计算结果是真的)或者更好的while True:。
第三,用户名/密码检查只检查最后一个用户和密码。如果使用userguess in store_user和相同的密码,则不会得到预期的结果。所以,你需要使用字典而不是列表。通过这些,您可以将键指定给值。在您的情况下,用户需要密码,因此您将拥有:store = dict()
# the code to get the user/password
store[user] = password # you "save" the value password for the key user
# then to check:
while not (userguess in store and store[userguess] == passwordguess):
# try again
多读一些字典。
然后,可以将每个“逻辑”过程存储在一个函数中,以使代码更具可读性和可重用性。例如ÿ