0

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! :(')
2
Contributors
1
Reply
25
Views
3 Years
Discussion Span
Last Post by John A.
0

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.

Edited by John A.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.