·Create an Account class to manage ID and Password
Create dictionary type private variable __data
·From now on, key is ID and value is Password
Create Initial Account in Constructor
·No arguments
·Initial account: ID is root Password is root
Register method for account registration
·The argument is id,pw
·Return value is "Registration complete"
Update method to update the account password if the password is correct
·The argument is the id of the account to be updated, the original password old_pw, the new password new_pw
·The return value is "Update complete" or "The password is incorrect"
Delete method to delete account if password is correct
·The argument is id,pw
·The return value is "Delete Complete" or "The password is incorrect"
·Create execution class
Create Account Class Objects
Repeat the process
until "End" is entered.
I would like to create a program like this, but it has stopped here.What should I do in the future?
The goal of the results is here.
Current source code:
class Account:
def__init__(self):
self.__data={'root':'root'}
@property
def register(self,id,pw):
id=input("Enter account name ->")
pw = input("Enter Password - >")
return "Registration complete"
@property
default (self, id, old_pw, new_pw):
id=input("Enter account name ->")
old_pw = input("Enter Old Password - >")
new_pw = input("Enter new password - >")
if self.if==id and self.pw==pw:
return "Update Complete"
else:
return "The password is invalid"
@property
def delete (self, id, pw):
id=input("Enter account name ->")
pw = input("Enter Password - >")
if self.id == id and self.pw == pw:
return "Delete Complete"
else:
return "The password is invalid"
print("1.Register\n2.Change\n3.Delete\n9.Finish")
while True:
a = input()
if a == 1:
print(f "Choose Action - > {a}")
ac=Account()
ac.register()
elifa==2:
print(f "Choose Action - > {a}")
ac=Account()
ac.update()
elifa==3:
print(f "Choose Action - > {a}")
ac=Account()
ac.delete()
elifa==9:
print ("Finish")
break
Are you working on a practice question or something?
Why don't you put aside the details and start here?
Python tutorial
Perhaps you should do the following.
#It is taboo to use reserved words as variable names.
class user_account():
def__init__(self):
self.user_account=dict()
# Need root user by default?
# Do I not need to encrypt my password?
def_root_password='root'
self.user_account.setdefault(
'root',
def_root_password,
)
def show (self):
print(self.user_account)
default (self):
user_id=input("Enter account name ->")
# Is it OK to display the password input?
# Do I need to reconfirm my password?
user_password=input("Enter Password - >")
# What about duplicate user_id?
self.user_account.setdefault(
user_id, user_password
)
print('Registration Complete')
self.show()
return
default (self):
user_id=input("Enter account name ->")
# Is it OK to display the password input?
# Do I need to reconfirm my password?
if user_id in self.user_account:
reg_password=self.user_account [user_id]
old_password=input("Enter Old Password - >")
if reg_password==old_password:
new_password=input("Enter new password - >")
self.user_account [user_id] = new_password
print('Update Complete')
else:
# What if the password is wrong?
pass
else:
# What if user_id wasn't registered?
pass
self.show()
return
def delete (self):
user_id=input("Enter account name ->")
# Is it OK to display the password input?
# Do I need to reconfirm my password?
# Can I turn off the root?
if user_id in self.user_account:
reg_password=self.user_account [user_id]
password = input("Enter Password - >")
if reg_password==password:
self.user_account.pop(user_id)
print('Delete Complete')
else:
# What if the password is wrong?
pass
else:
# What if user_id wasn't registered?
pass
self.show()
return
instAccount=user_account()
while True:
print("1.Register\n2.Change\n3.Delete\n9.Finish")
a = input ('key input:')
print(f "Choose Action - > {a}")
if a=='1':
instAccount.entry()
elifa=='2':
instAccount.update()
elifa=='3':
instAccount.delete()
elifa=='9':
print ("Finish")
break
© 2024 OneMinuteCode. All rights reserved.