python唯一的用户名和密码

时间:2018-07-06 11:25:08

标签: python python-3.x

我希望此代码成为可以存储用户名和密码以及每个用户详细信息的代码

name = (input('what is your name '))
age = (input('what is your age '))
(print('please wait your username is processing...'))
import time
time.sleep(5)
(print(name[:3]+age))
password1 = (input('what is your password '))
(print('your details are saved. You can now log in'))
import time
time.sleep(3)
(input('What is your username')
username == name
(input('what is your password')
password = password1
 (print('you are now logged in')

1 个答案:

答案 0 :(得分:1)

最简单地说,您可以将输入存储在Python字典中,以用户名作为键,密码作为值,例如:

user = dict()
user.update({name:password1})

通过将其存储在字典中,将确保用户名始终是唯一的。而当您想与用户名输入匹配时,您可以执行以下操作:

if username in user:
  //do some processing