Kids Coding

Project: Scored Quiz

Questions in a list of dicts. Track score. Print a result you can explain.

KidsAdvancedProject: Scored Quiz

Questions as data

Store each question as a dict. Loop the list. Compare answers. Keep a score. Now adding a question is one more dict, not a new if block.

Quiz from a table

questions = [
    {"prompt": "2 + 2?", "answer": "4"},
    {"prompt": "Colour of the sky?", "answer": "blue"},
    {"prompt": "A sly animal?", "answer": "fox"},
]
given = ["4", "green", "fox"]

score = 0
for i, item in enumerate(questions):
    print(item["prompt"])
    print("You said:", given[i])
    if given[i] == item["answer"]:
        print("Correct")
        score = score + 1
    else:
        print("It was", item["answer"])
    print()

print("Score:", score, "/", len(questions))

Check the answer first, then add to the score once. A misplaced += 1 is why a quiz sometimes gives 6 out of 5.

Real life

A spelling test: the questions live on a sheet, the ticks live in a score.

Put the questions in data. The loop is the test. Adding a word is one more dict.

Spelling test

words = [
    {"ask": "cat", "answer": "cat"},
    {"ask": "fox", "answer": "fox"},
]
given = ["cat", "fos"]
score = 0
for i, item in enumerate(words):
    if given[i] == item["answer"]:
        score = score + 1
print("Spelling:", score, "/", len(words))

Change one word. Run it. That is how this idea shows up outside the lesson.

Try it

Exercise 1: Make a list with one question dict. If given matches answer, print ok.

Show solution
item = {"prompt": "1+1?", "answer": "2"}
given = "2"
if given == item["answer"]:
    print("ok")

FAQ: Project: Scored Quiz

Common questions about this page.

What is StudyGrid Kids?

StudyGrid Kids is a free coding path for children: Basic, Intermediate, and Advanced. Lessons use Python in the browser. No account and no install.

Should I run project: scored quiz examples locally for better learning?

Yes. Use the browser editor on StudyGrid for a quick check, then Download the example and run it on your computer. Local runs show real errors and the real toolchain, which is one of the fastest ways to learn project: scored quiz in this Kids Coding Python lesson (Project: Scored Quiz).

Which kids level should we start with?

Start at Basic if the child has never written code. Choose Intermediate if they can print, use variables, and write a simple if. Choose Advanced if they already use loops and lists.

Do kids need an account or an app?

No. Kids pages are public. Code runs in the Try Python editor at /try. We do not ask children for a name or an email.

What language do kids learn?

Python, with a first HTML page in Intermediate and Advanced. After Advanced, the main Python tutorial is the next step.

Is the kids coding track free?

Yes. The Kids home, the three levels, and the Python editor on StudyGrid (studygrid.in) are free.