pnew 到 python,我正在玩元组中的列表。我只想删除密码而不是用户名,并在删除密码后更新密码,但是我测试了代码以发现它删除了整个元组和元组中的列表,然后它给了我 IndexError: list index超出范围....任何帮助将不胜感激。
Users=[("Jim","password1"),("Bob","password2"),("Helen","password3"),("Beverly","blue")]
def changePassword():
a=raw_input("Enter old password to continue:\n")
for i in range(len(Users)):
c,d=Users[i]
if a==d:
Users.remove(Users[i])
print "Password deleted"
print Users
if a!=d:
print"Incorrect"
changePassword()
a=raw_input("Enter new password:\n")
for i in range(len(Users)):
c,d=Users[i]
if a==d:
Users.append(Users[i])
changePassword()