usr=[] passwd=[] while True: choise = input("输入1为注册,输入2为修改,其它字符就退出:") if choise == "1": while True: username=input("请输入账户:") if username in usr: print("账户已经存在,请重新输入") continue while True: password = input("请输入密码:") newpassward = input("请再次输入密码:") if password == newpassward: print("注册成功") usr.append(username) break else: print("两次密码不一致请重新输入:") # usr.append(username) print("已经注册的账户:",usr) if choise == "2": list[usr]=1 print(list)补充完整
时间: 2024-02-14 20:26:42 浏览: 28
你的代码有一些错误和不完整的地方,我来帮你补充完整。
```python
usr = []
passwd = []
while True:
choice = input("输入1为注册,输入2为修改,其它字符就退出:")
if choice == "1":
while True:
username = input("请输入账户:")
if username in usr:
print("账户已经存在,请重新输入")
continue
password = input("请输入密码:")
new_password = input("请再次输入密码:")
if password == new_password:
usr.append(username)
passwd.append(password)
print("注册成功")
break
else:
print("两次密码不一致,请重新输入")
print("已经注册的账户:", usr)
elif choice == "2":
if len(usr) == 0:
print("还没有注册任何账户")
continue
username = input("请输入要修改密码的账户:")
if username not in usr:
print("账户不存在")
continue
password = input("请输入新密码:")
new_password = input("请再次输入新密码:")
if password == new_password:
index = usr.index(username)
passwd[index] = password
print("密码修改成功")
else:
print("两次密码不一致")
else:
break
```
这段代码实现了一个简单的注册和修改密码的功能。用户可以选择注册或者修改密码,注册时要求输入用户名和密码,并进行验证;修改密码时要求输入已注册的用户名和新密码,并进行验证。同时,代码会保存已注册的用户名和对应的密码。
注意:这段代码并没有进行任何安全性的处理,仅作为示例,请勿在实际项目中使用。在实际开发中,应该使用加密算法对用户密码进行加密存储,并进行其他安全性的处理。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)