基本python密码保险库,回答重复不停止和其他问题

问题描述 投票:0回答:1

我的评估是构建一个密码保险库,包括基本的python列表,功能while循环等,但在用户实际为其应用程序输入密码的部分遇到问题。第一个问题是,当他们要求查看他们的密码并且没有任何应该说"you have nothing stored"时,它说这个但不要停止重复它,并且还想知道我是否可以得到一些帮助来完成其余部分。这就是我希望这部分代码在使用它时的样子。

按:1)找到您现有的密码2)为您的应用程序保存一个新密码3)查看密码锁的摘要4)成功退出密码锁2

网站名称:Facebook

网站用户名:bob91

网站密码:bob95

你想添加另一个应用程序:是的

网站名称:Instagram

网站用户名:albert91

网站密码:albert95

你想添加另一个应用程序:没有

按:1)找到您现有的密码2)为您的应用程序保存新密码3)查看密码锁的摘要4)成功退出密码锁1您想要访问哪个应用程序密码:Facebook Facebook

用户名:bob91

密码:bob95

--------------------------------------------------我现在的实际代码 - >


vault_apps = []           
app_name = ""
def locker_menu_func():
    print('''You have opened the locker, 
Please select what you would like to do,''')
    while True:
        locker_menu_var = input('''Press: \n1) find your existing passwords \n2) save a new password for your apps
3) see a summary of your password locke \n4) exit password locker successfully
---------------------------------------------------------------------------------
''')
        print('''----------------------------------------------------------------''')
        if locker_menu_var == "1":
            while len(vault_apps) < 1: 
                print('''you have nothing stored''') 
                break
            break
        elif locker_menu_var == "2":
            app_name = input('''
What is the name of the website/app your are adding?
''')
            app_password = input('''What is the password of your {} account?
'''.format(app_name))
            vault_apps.append([app_name, app_password])
            while True: another_app = input('''Would you like to add another app to your password locker?''')
            if another_app in {"Y", "YES"}:
                    print("okay")
                    break    

            break        

locker_menu_func()
python python-3.x
1个回答
1
投票

我用字典来存储密码。试试这种方式。如果它解决了你的问题,请亲自投票并将其作为答案。

app_passwords = {}

def locker_menu_func():
    print('''You have opened the locker, 
Please select what you would like to do,''')

    while True:
        locker_menu_var = input('''Press: \n1) find your existing passwords \n2) save a new password for your apps
3) see a summary of your password locke \n4) exit password locker successfully''')
        if locker_menu_var == "1":
            while len(app_passwords) < 1: 
                print('''you hve nothing stored''')           
                break
            else:
                for kv in app_passwords.items():
                    a=  kv[0],kv[1]
                    print(str(a).replace("(","").replace(")","").replace("[","").replace("]",""))
                #print (app_passwords)

        elif locker_menu_var == "2":
            web = input("Enter Website")
            username = input("Enter username")
            password = input("Enter password")
            app_passwords[web]=["username:"+username+","+"password:"+password]
        elif locker_menu_var == "3":
            print ("Count of Websites stored",len(app_passwords))
        elif locker_menu_var == "4":
            break


locker_menu_func()
© www.soinside.com 2019 - 2024. All rights reserved.