I have the following:
import sqlite3
# connecting to the database
conn = sqlite3.connect("illness.db")
question_data = [
{
"question1": "Have you consumed Alcoholic drinks in the last 24 hours?t",
"choices": {"a": "Yes", "b": "No"},
"answer": "a"
},
{
"question2": "Another Question",
"choices": {"a": "choice 1", "b": "choice 2", "c": "choice 3"},
}
]
q = (question_data)
print(q.get('question1'))
answer = input(q.get('choices')).lower()
if answer == q.get('answer'):
c = conn.execute("SELECT illnessID, illness, illnessinfo from illnesses WHERE illness = 'Alcohol Misuse'")
else:
print("Okay Next question.")
This corresponds to:
def create_table():
c.execute("CREATE TABLE IF NOT EXISTS illnesses(illnessID PRIMARY KEY, illness VARCHAR(30), illnessinfo VARCHAR(50))")
c.execute("CREATE TABLE IF NOT EXISTS symptoms(symptomID PRIMARY KEY, symptom VARCHAR(50))")
def data_entry():
c.execute("INSERT INTO illnesses(illnessID, illness , illnessinfo) VALUES(1,'Flu','Influenza - Common Cold.')")
c.execute("INSERT INTO illnesses(illnessID, illness , illnessinfo) VALUES(2,'Acne','Skin Condition')")
c.execute("INSERT INTO illnesses(illnessID, illness , illnessinfo) VALUES(3,'Alcohol Misuse','Hangover')")
c.execute("INSERT INTO symptoms (symptomID,symptom) VALUES(1,'Headache')")
c.execute("INSERT INTO symptoms (symptomID,symptom) VALUES(2,'Spots')")
c.execute("INSERT INTO symptoms (symptomID,symptom) VALUES(3,'Breathing problems')")
So there I have a minimal DB and a form of a questionnaire which I'm trying to have questions relate to answers inside the DB which then tell me which illness it is then print that out into a text file. However I am new to all this and i'm trying to figure it all out and I'm honestly just really stuck and unsure where to go from here. Any help at all from this would be appreciated.
EDIT: The error message I get is: object has no attribute 'get'
object has no attribute 'get'. Just in general not sure whats the next move.