displaying whole lists, where the user can interact with

Question:

My program is meant to show people their password for apps when they enter it, but for some reason its not showing all the app names they have entered in the line print('''here are your apps, {} which ones information do you want to view'''.format(a[0]) here if the user has previously entered their information for YouTube, Facebook etc., it should print out print(”’there are your apps, YouTube, Facebook
which ones information do you want to view”’.format(a[0]))
and then the user will type which one and it will show their password for it.

vault_apps = []           

users_passwords = ""
def existing_apps(): 
    if len(vault_apps) < 1:
        print('''you have currently 0 app and passwords stored on your account''')
        locker_menu_func()
    else:
        for a in vault_apps:
            print('''here are your apps, {}
which ones information do you want to view'''.format(a[0]))
            break
            
        while True: 
            users_passwords = input('''
''')
            if users_passwords == "":
                print('''Please enter a valid answer''')
            else:
                for a in vault_apps:
                    if users_passwords in a:
                        print('''{}
password: {}'''.format(users_passwords, a[1]))


def store_apps(): 
            while True: 
                        app_name = input('''What is the name of the website/app your are adding?
''') 
                        if 0 < len(app_name) < 16:
                                    break
                        elif app_name == "":
                                    print("Please enter an answer")
            while True:
                        app_password = input('''What is the password of your {} account?
'''.format(app_name))                        
                        if app_password == "":
                                    print("Please enter an answer")
                        else: vault_apps.append([app_name, app_password])
                        break
            while True:
                        add_app = input('''would you like to add another app and password, yes or no
''')
                        
                        if add_app.lower() == "no":
                            locker_menu_func()
                        elif add_app.lower() == "yes":
                            store_apps()
                        else: 
                            print("please enter a proper answer")
                            
                        
                        
                        
                        

def locker_menu_func():
            print('''You have opened the locker, 
Please select what you would like to do,''')
            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('''----------------------------------------------------------------''')    
            while True:
                        if locker_menu_var == "1": existing_apps()

           
                        if locker_menu_var == "2": store_apps()
                        locker_menu_func()
                        break
locker_menu_func()
Asked By: user11289453

||

Answers:

The problem is in your existing_apps method. You are iterating over vault_apps but you are breaking once you have printed the first value.

I’ve added a modification where we get the list of names using a list comprehension, join it using join() and then print the values.

Note also a nice formatting trick where you can use f"{some_variable}" instead of "{}".format(variable)

def existing_apps(): 
    if len(vault_apps) < 1:
        print('''you have currently 0 app and passwords stored on your account''')
        locker_menu_func()
    # PLEASE LOOK AT THE BELOW PORTION
    else:
        app_names = [x[0] for x in vault_apps]
        app_names_pretty = ", ".join(app_names)
        print(f'here are your apps, {app_names_pretty} | which ones information do you want to view')
        # END OF MODIFICATION 
        while True: 
            users_passwords = input()
            if users_passwords == "":
                print('''Please enter a valid answer''')
            else:
                for a in vault_apps:
                    if users_passwords in a:
                        print('''{}password: {}'''.format(users_passwords, a[1]))
Answered By: raghav710
  1. you are breaking on the very first found app here:

..

for a in vault_apps:
     print('''here are your apps, {}which ones information do you want to view'''.format(a[0]))
     break
  1. You are not checking for what if the user enters an invalid app name, to which the password does not exist here:

..

 for a in vault_apps:
      if users_passwords in a:
           print('''{}password: {}'''.format(users_passwords, a[1]))
  1. You need to put a check for invalid app names as well:

..

if any(app_name in sl for sl in vault_apps):
  1. You need to put a quit statement in there for if a user does not want to continue further:

..

app_name = input("Enter the app name to view its password or Q to quit: ")
if app_name.lower() == "q" : exit("Thank you, see you again!")

Hence:

def existing_apps():
if len(vault_apps) < 1:
    print("you have currently 0 app and passwords stored on your account")
    locker_menu_func()
else:
    print("here are your apps, {}".format([str(x[0]) for x in vault_apps]))
    while True:
        app_name = input("Enter the app name to view its password or Q to quit: ")
        if app_name.lower() == "q" : exit("Thank you, see you again!")
        else:
            if any(app_name in sl for sl in vault_apps):
                for a in vault_apps:
                    if app_name in a: print("{} password: {}".format(app_name, a[1]))
            else: print("Invalid app name!")

OUTPUT:

What is the name of the website/app your are adding?facebook
What is the password of your facebook account?face123
would you like to add another app and password, yes or noyes
What is the name of the website/app your are adding?stackoverflow
What is the password of your stackoverflow account?stack123
would you like to add another app and password, yes or nono
You have opened the locker, 
Please select what you would like to do,
Press: 
1) find your existing passwords 
2) save a new password for your apps
3) see a summary of your password locke 
4) exit password locker successfully
---------------------------------------------------------------------------------
1
----------------------------------------------------------------
here are your apps, ['facebook', 'stackoverflow']
Enter the app name to view its password: stackoverflow
stackoverflow password: stack123
Enter the app name to view its password: facebook
facebook password: face123
Enter the app name to view its password: myspace
Invalid app name!
Enter the app name to view its password or Q to quit: q
Thank you, see you again! 
Answered By: DirtyBit
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.