简单的python登录程序

时间:2018-01-21 23:04:39

标签: python

UserList = []
PassList = []

print("Welcome to GipCo/n")

ans = input("Do you have an account with GipCo? please enter y/n:")

if ans == 'n':
    User = input("Please type your username: ")
    UserList.append(User)
    Pass = input("Please type your password: ")
    PassList.append(Pass)
    print(UserList,PassList)
    print("You have created your new accoutn with GipCo, please login\n")
    User1 = input("Please enter your username: ")
    Pass1 = input("Please enter your password: ")
    if User1 == (UserList) and Pass1 == (PassList):
        print("Welcome to GipCo, type MENU to enter: ")

    else:
        print("Incorrect username or Password")

`

为什么不工作,我在User and Pass中输入用户名和密码,将其添加到列表中,但登录时不会调用列表,只是说它是错误的。

3 个答案:

答案 0 :(得分:2)

User1Pass1是字符串;正如他们的名字所示,UserListPassList列出了。没有字符串可以等于列表。

答案 1 :(得分:2)

那是因为您将类型数组的UserList与String进行比较,因此它将在那里返回false:

 if User1 == (UserList) and Pass1 == (PassList)

答案 2 :(得分:1)

if User1 == (UserList) and Pass1 == (PassList):

您尚未在列表中搜索信息

if User1 in UserList:     #is User1 in the list? 
   if Pass1 == PassList[UserList.index(User1)]:
      print ("Log in Success")
相关问题