我已经经历了大部分相关的问题,并且他们都没有给我提供我需要的程序的想法。使用if if语句检查列表
users = ["Block Harris",
"Apple Mccoy",
"Plays Terry",
"Michael Strong",
"Katie Blue"]
nicknames = ["Block",
"Apple",
"Plays",
"Michael",
"Katie"]
passwords = ["abc",
"def",
"ghi",
"jkl",
"mno"]
levels = [5,2,1,4,3]
security = 0
found_user = False
username = ""
while not username:
username = input("Username: ")
password = ""
while not password:
password = input("Password: ")
for i in range(5):
if username == users[i]:
found_user = True
if password == passwords[i]:
security = levels[i]
print("Welcome, ", nicknames[i])
break
else:
print("Sorry, you don't know the password.")
if found_user == levels[0]:
print("Security level 1: You have little privelages. Congratulations.")
elif found_user == levels[1]:
print("Security level 2: You have more than little privelages. Congratulations.")
elif found_user == levels[2]:
print("Security level 3: You have average privelages. Congratulations.")
elif found_user == levels[3]:
print("Security level 4: You have more than average privelages. Congratulations.")
elif found_user == levels[4]:
print("Security level 5: You have wizard privelages. Congratulations.")
else:
print("Apparently you don't exist.")
data_network()
什么我想在这里做的是试图测试各个成员的安全级别或发现数据库中的用户,然后使用if-else语句根据自己的安全级别打印相应的消息下面。我不知道该程序在做什么,但它不是根据列表中的级别评估找到的用户。例如,对于第一个人,列表中的级别相应为5,但它会输出“找到用户==级别[2]”的消息。
Upvoted,但我可能会将“return -1”替换为“return None”。 – 2011-03-02 01:31:52
@Jeff Bauer Duly注意到并改变了。 – wheaties 2011-03-02 01:33:37