Regarding the same problem in my last question, but now my program is running fine but not returning what i want. The question is: Write a class called Password_manager. The class should have a list called old_passwords that holds all of the user’s past passwords. The last item of the list is the user’s current password. There should be a method called get_password that returns the current password and a method called set_password that sets the user’s password. The set_password method should only change the password if the attempted password is different from all the user’s past passwords. Finally, create a method called is_correct that receives a string and returns a boolean True or False depending on whether the string is equal to the current password or not.
I have created a list of 5 letters. Next i defined my class and three instance methods. First method - get_password which returns the last letter in my list; Second method - set_password. If the letter i input is not in my list i need to return another number, randomly generated. Third and last method - method that returns bollean expressions. If the letter i input is the current letter (last one in the list) i return True, else i return False.
import random
old_password=['a','b','c','d']
class Password_manager:
def __init__(self,old_password):
self.old_password=old_password
def get_password(self):
return self.old_password[len(self.old_password)-1]
def set_password(self):
if string not in self.old_password:
return random.choice(self.old_password)
def is_correct(self):
current_password=self.get_password()
if string==current_password:
return True
else:
return False
string=Password_manager(input('Digit password\n'))
print(string.is_correct())
My program always return False whenever i input a letter that exists in my list or any other letter. Basically my program skips the first if clause.
Aucun commentaire:
Enregistrer un commentaire