Aug-02-2023, 02:49 AM
(This post was last modified: Aug-02-2023, 05:27 AM by Gribouillis.)
Hey team,
I have worked on a piece of code that should be able to read my question on sustainability and produce me an answer with some ideas based on what I asked it.
The code loads so I can test the instance but it doesn't produce an answer?
The code is
I can ask the question but no answer is delivered. Can someone please advise if I have missed a step for a reason to why I can see the answer being submitted?
I have worked on a piece of code that should be able to read my question on sustainability and produce me an answer with some ideas based on what I asked it.
The code loads so I can test the instance but it doesn't produce an answer?
The code is
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import random import json # Create a list of questions and answers about sustainability questions = [ "How can I reduce the environmental impact of my event?" , "What are some sustainable catering options?" , "How can I encourage people to use public transportation to my event?" , "How can I reduce the amount of waste at my event?" , "How can I make my event more accessible to people with disabilities?" , "What is the most sustainable food?" , ] def new_func(): return "Here are some tips on how to reduce the environmental impact of your event:\n" answers = [new_func().strip()] # Create a database to store the questions and answers database = {} # Create a function to answer a question def answer_question(question): if question in database: return database[question] else : keywords = question.split() for keyword in keywords: if keyword in database: return database[keyword] answer = random.choice(answers) database[question] = answer return answer # Create a function to start the web app def start_web_app(): print ( "Welcome to the sustainability web app!" ) print ( "What question would you like me to answer?" ) question = input () answer = answer_question(question) print (answer) # Start the web app start_web_app() |
Gribouillis write Aug-02-2023, 05:27 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.