I have this code that works well. It works in a way that I have to type a function such as soccer for the games.soccer module to be active then i can type a query such as 'latest scores', again after i close this then type autocare for this to work.. I need help in coding a way to just type the query e.g 'latest scores'..then this will iterate over all imported functions in the PLAY dictionary to find the answer.Here is the code

import games
import clauseq11
PLAY = {
    'soccer': games.soccer,
    'nba': games.nba,
    'autorace': games.autorace,
    'search_name': clauseq11.search_name,
    'answer_neg1': clauseq11.answer_neg1,
    }

while True:
    question = input('Please enter your question: ').lower()
    if not question:
        break
    for key, func in PLAY.items():             
        if key in question:
            func()
            break
    else:
        print('Sorry I do not have an answer! :(')
Member Avatar for John A.

Well I just started Python myself, but I believe you could do something like

for key in PLAY:
    PLAY[KEY]

Sorry, if this isn't what you wanted.

EDIT: I didn't realize how old the post was.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.