Letter from a Prepper – Teaching Math with Python

So Childish Meteor has known the crude mechanics of Math for a while now.  We bought him some educational videos early on that taught him the Letters, Numbers, Shapes, and Colors and they worked so well that when they expanded their offering we could not resist getting the Math Videos as well.

But now that he is in Kindergarten he is learning and practicing more addition and subtraction for his classes.  He is having to apply what he learned and work out the problems in the assignment.

Making it a Game

At first, he started out wanting to use a calculator, and once I taught him a little Python he wanted to use scripts to do his homework too.  I wanted to use python to reinforce his learning without having it do it for him.  So, I helped him work out a simple subtraction game to practice his subtraction for school.

from random import *

print ("Welcome to our Subtraction Game")
score = 0

while score < 100:
    x = randint(1, 10)
    y = randint(x, 10)

    print("What is", x ,"-", y, "?")
    answer = input()

    correct = (x - y)

    if answer == str(correct):
        print("Your answer is correct!")
        score = score + 10
        print("Your Score is",score,"Points") 
    else:
        print("The Correct answer is:", correct, "Try again!")
        score = score - 10
        print("Your Score is",score,"Points")

print("YOU WIN!")

We modeled the game off an example we found in Hello World!: Computer Programming for Kids and Other Beginners for a number guessing game featuring the Dread Pirate Roberts of Princess Bride fame.

We worked out a way for it to select random numbers and create unique math problems each time using the random module.  We also made it so it keeps score and allows you to win after getting 100 points, adding 10 for each right answer and taking away 10 for each wrong one.

It has been working great in getting him to practice his subtraction problems.   He still wants to use a calculator or write another python script but I make him give me the answer before we “check” his work with either one.  It seems to be an acceptable compromise for now.

How do you get creative with your Math Practice?

LEAVE A REPLY

Please enter your comment!
Please enter your name here