importpickleclassUser:def__init__(self,username,password):self.username=username
self.password=passworddefset_password(self):self.password=input("Enter NEW password > ")def__get_password(self):returnself.passworddef__get_username(self):returnself.usernamedefchange_password(self):my_password=input("Enter your CURRENT password > ")ifmy_password==User.__get_password(self):self.set_password()else:print("Please try again")defdisplay_details(self):print()print("Username and password")print("---------------------")print("username is: ",User.__get_username(self))print("password is: ",User.__get_password(self))print()def__repr__(self):returnf'username: {self.username}'users=[User("MichaelPalin","P4rr0t"),User("EricIdle","M0nty"),User("TerryJones","Pyth0n")]try:foo=pickle.load(open("users.pickle","rb"))except(OSError,IOError)asf:foo=3pickle.dump(foo,open("users.pickle","wb"))# with open('users.pickle', 'wb') as f:# pickle.dump(users, f)deffind_user(name):foruserinusers:ifuser.username==name:returnuserdefadd_user():user=input("Enter NEW user > ")password=input(f"Enter password for {user} > ")users.append(User(user,password))defdelete_user():delete_user=input("Enter the user you wish to remove > ")user=find_user(delete_user)ifuser:users.remove(user)print('done')else:print(f'user {delete_user} not found')defchange_password():my_password=input("Enter your CURRENT password > ")change_password()defdisplay_users():foruserinusers:print(user)definvalid_entry():# Response for invalid entries to menu.print("Invalid entry, please try again")print()defmenu():# Display menu, prompt for and accept keyboard choiceprint("Please select one of the following:")print()print("Enter a if you want to add a new user")print("Enter d if you want to delete a user")print("Enter f if you want to find a user")print("Enter c if you want to change your password")print("Enter u if you want to display a list of users")print("Enter q if you want to Quit")choice=input("")returnchoicewhileTrue:menu_choice=menu()ifmenu_choice.lower()=="a":add_user()elifmenu_choice.lower()=="d":delete_user()elifmenu_choice.lower()=="f":find_user()elifmenu_choice.lower()=="c":change_password()elifmenu_choice.lower()=='u':display_users()elifmenu_choice.lower()=="q":print("Goodbye")withopen('users.pickle','wb')asf:pickle.dump(users,f)quit()else:invalid_entry()