我如何将新用户和引脚添加到此列表
users = {'name': '1234', 'name2': '5678', 'name3': '9012'}
status = ""
if status == "n":
create_userName = raw_input("Create login name: ")
if create_userName in users: # check if login name exists
print "\nLogin name already exist!\n"
else:
create_passWord = raw_input("Create password: ")
users[create_userName] = create_passWord # add login and password
print("\nUser created!\n")
答案 0 :(得分:0)
我不确定你的问题是什么,但我刚刚删除了
if status = "n":
部分是因为该部分程序永远不会执行原因状态永远不会变成'n'......
users = {'name': '1234', 'name2': '5678', 'name3': '9012'}
create_userName = input("Create login name: ")
if create_userName in users: # check if login name exists
print ("\nLogin name already exist!\n")
else:
create_passWord = input("Create password: ")
users[create_userName] = create_passWord # add login and password
print("\nUser created!\n")
我希望这有用。