Kids Coding
Project: Quiz
Ask three questions. Keep a score. Print how you did.
KidsIntermediateProject: Quiz
Three questions, one score
Keep score in a box. For each question, check the answer. Add 1 when it is right. Print the total at the end.
A three-question quiz
score = 0
q1 = "blue"
if q1 == "blue":
print("1. Yes")
score = score + 1
else:
print("1. No")
q2 = "4"
if q2 == "4":
print("2. Yes")
score = score + 1
else:
print("2. No")
q3 = "fox"
if q3 == "fox":
print("3. Yes")
score = score + 1
else:
print("3. No")
print("Score:", score, "out of 3")Keep the questions and answers in a list, then loop over them. Ten questions become the same few lines as one.
Make it yours
- Change the questions.
- Use a list of answers later if you want less copy-paste.
- On a computer, each
qcan beinput(...).
Real life
A three-question animal quiz in science class.
Each right answer adds a mark. score = score + 1 is the tick on the paper.
Science quiz
score = 0
if "whale" == "whale":
score = score + 1
if "insect" == "spider":
score = score + 1
else:
print("Spiders are not insects")
print("Marks:", score, "/ 2")Change one word. Run it. That is how this idea shows up outside the lesson.
Try it
Exercise 1: One question: if answer is 2, add a point and print Score: 1.
Show solution
score = 0
answer = "2"
if answer == "2":
score = score + 1
print("Score:", score)