A few comments:
I just saw your other thread where you do use list, not dict
https://python-forum.io/Thread-Display-L...User-Input
I will not merge both threads as the other one is much older, but I post this link for completeness.
- db_list - this variable name implies that it's a list, while in fact you have dict. You may decide to switch to list (see my next comment)
- dict is not ordered. In python3.6 the order of elements is preserved, but according to docs this is considered implementation detail and should not be relied upon. In other words the order in which you print dict items may be different from what you expect.
- line#13 - I expect you want to use name, not x. As it is now x is the last item from previous for loop, thus will always be present in db_list.keys(). Here keys() is not necessary, in always checks in dict.keys() by default
- line #15 - again you want to use name (i.e. the user input from line#11, not x
I just saw your other thread where you do use list, not dict
https://python-forum.io/Thread-Display-L...User-Input
I will not merge both threads as the other one is much older, but I post this link for completeness.
db_list = ['TEST11C', 'TEST12C'] print("Available Databases:") for i, db_name in enumerate(db_list, start=1): print ('{}. {}'.format(i, db_name)) while True: try: selected = int(input('Select a database (1-{}): '.format(i))) db_name = db_list[selected-1] print('You have selected {}'.format(db_name)) break except (ValueError, IndexError): print('This is not a valid selection. Please enter number between 1 and {}!'.format(i))
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs