I am having issues finding a way to have the below program search for any given string of "query" in the keys of the dictionary AB and return the value, or the key and value. Thus far I just done what I have preset in the dictionary; Ashley and Joshua, and they are retrievable via a very simple code, that is unrealistic if I wanted users to be able to create and search from their own Address Book dictionary.
#Address Book#
#Remember brackets call object from library []#
#only add dicts to dicts; add via dictname.update(var)
AB={'Joshua' : 'Joshua: ''Email: sho0uk0m0o@gmail.com Phone: (802) 3-5-2206',
'Ashley' : 'Ashley: ''Email: a000@gmail.com Phone: (802) 820-0000',}
print('Address Book: Enter x into query to exit')
print('to add a contact enter "add" in query')
query = input('Enter Search Query: ')
##abkeys=AB.keys()
##abvals=AB.values()
while query!=('x'):
if ('add')in query:
new={input('Enter name: '): input('utilize the following format: Name______,:, Email,:,______, Phone,:,______ Enter contact information: ')}
AB.update(new)
print(AB)
query=input('Enter Search Query: ')
## if query in AB:
## print(AB.keys(),AB.values())
elif ('as') in query or ('As') in query:
print(AB['Ashley'])
query= input('Enter Search Query:' )
elif ('jo') in query or ('Jo') in query:
print(AB['Joshua'])
query=input('Enter Search Query:' )
elif query==('0'):
print(AB['Joshua'])
print(AB['Ashley'])
query=('x')
else:
print('Query not found please retype your query or type "help" for more information')
query = input('Enter Search Query: ')
if ('x') in query or query==('x'):
print('Application Terminated')
#Next, find a way to search based on any given input == str in key from AB and print key,value