For this worksheet, we are going to create a matrix of dictionary to store some questions and answers about Maths, Physics and Chemistry. We are going to achieve this through 2 steps. Sounds easy, but we have to care about details.
Create dictionary to store pair of questions and answers
Create list including dictionaries
dictionary={"question": "What method do we use to calculate the slope of a graph?", "answer": "differentiation"}
In this case, we created a dictionary contains 2 keys "question" and "answer" and values(string) corresponding to two keys "What method do we use to calculate the slope of a graph?" and "differentiation".
*We use double quotation mark "" and braces {} when we use strings in dictionary.
Furthermore, we can create a list including 4 dictionary elements storing 2 pairs of questions and answers:
list =
[
{"question":"Name?", "answer": "Bill"},
{"question":"Interest?", "answer": "Boxing"}
]
And now we can store our questions and answers into a dictionary matrix! So for the Maths problems we can create a matrix as below:
mathEntries = [
{"question": "What method do we use to calculate the slope of a graph?", "answer": "differentiation"},
{"question": "Whose theorem states that in a triangle: a^2 = b^2 + c ^2?", "answer": "pythagoras"},
{"question": "What is the type of the following function: x^2 + x + 4?", "answer": "quadratic"},
{"question": "If the determinant of a quadratic equation is greater than 0, how many roots are there?", "answer": "two"}
]
Follow the materials above to create the dictionary matrix for following question and answers.
chemistryEntries = [
{"question":"What is the chemical composition of water?", "answer": "H2O"},
{"question":"What does Mg stand for?", "answer": "magnesium"},
{"question":"What type of bonding is there betwwn Fe atoms?", "answer": "metallic"},
{"question":"Which sub atomic particle has a positive charge?", "answer": "protons"},
{"question":"What are atoms with the same amount of protons but a different mass number?", "answer": "isotopes"},
{"question":"What does K stand for?", "answer": "potassium"},
]
mathEntries = [
{"question": "What method do we use to calculate the slope of a graph?", "answer": "differentiation"},
{"question": "Whose theorem states that in a triangle: a^2 = b^2 + c ^2?", "answer": "pythagoras"},
{"question": "What is the type of the following function: x^2 + x + 4?", "answer": "quadratic"},
{"question": "If the determinant of a quadratic equation is greater than 0, how many roots are there?", "answer": "two"},
]
physicsEntries = [
{"question": "Does a metal expand when heated?", "answer": "yes"},
{"question": "In what units do we measure resitance?", "answer": "ohms"},
{"question": "What type of lens does a magnifying glass have?", "answer": "convex"},
{"question": "What is the correct formula for momentum?", "answer": "mxv"},
]