Coding Curriculum - Python

Worksheet 2

Goal

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.

  1. Create dictionary to store pair of questions and answers

  2. Create list including dictionaries

Step 1: Using dictionary

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.

Step 2: Put dictionaries into list

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"}
]

Do it yourself:

Follow the materials above to create the dictionary matrix for following question and answers.

Physics:

  • question: Does a metal expand when heated? Answer :yes
  • question: In what units do we measure resistance? Answer :ohms
  • question: What type of lens does a magnifying glass have? Answer :convex
  • question: What is the correct formula for momentum? Answer :mxv

Chemistry:

  • 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 between 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

The complete code for 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"},
]

Well done guys, you can use now dictionary and lists properly!.