A Math Worksheets Generator

So, I finally got tired of my son's dismal math performance at school, and decided to be more involved with his math life. I am not going to say anything about Common Core Math. OK, I guess I just did, but promise won't say no more on that topic :)

My plan is actually quite simple, and we shall see how it will work out. I told him that he needed to do 20 questions everyday, roughly equal parts for addition, subtraction and multiplication. For now, I am not too worried about divisions. They need to be 2-digit by 2-digit, and need to be done in his head :) And to top it off, he will write the program to generate the daily questions.

Initially, I thought about making it completely interactive, i.e., a math problem is displayed on the screen, it will wait for an answer (with a timer if necessary), check the answer, add it to the tally, and finally gives the grade after all 20 questions are completed.

 

But there is a special allure to paper and pencil. Plus, math quizzes in classroom will be done with paper and pencil -- for now.

 

So, here is the end product. Actually this is a revision from V1, created about a week ago. He doesn't quite have the sense of revisions yet, and I don't quite want to discuss TFS with him either :)

The upshot is that I don't have V1 no more. What you are looking at now is V2. Suffice it to say that he has made a bunch of improvements and cleaned up his code quite a bit.

 

Here is the code:

 

'Master control system

Date = "2014-04-29"

 

SubtrationMax = 99

SubtrationMin = 10

 

AdditionMax = 99

AdditionMin = 10

 

MultiplicationMax = 59

MultiplicationMin = 10

 

TxtLocation = "C:\Math\"

 

'Creating file in specific location

filename = TxtLocation + Date + ".txt"

 

'Creating inside text

File.WriteContents(filename, "Math Practice for " + Date)

File.AppendContents(filename, "")

File.AppendContents(filename, "")

File.AppendContents(filename, "")

 

'Starting a loop

For i = 1 To 20

   'Getting random numbers

    SubNumber1 = Math.GetRandomNumber(SubtrationMax - SubtrationMin + 1) - 1 + SubtrationMin

    SubNumber2 = Math.GetRandomNumber(SubtrationMax - SubtrationMin + 1) - 1 + SubtrationMin

 

    AddNumber1 = Math.GetRandomNumber(AdditionMax - AdditionMin + 1) - 1 + AdditionMin

    AddNumber2 = Math.GetRandomNumber(AdditionMax - AdditionMin + 1) - 1 + AdditionMin

 

    MulNumber1 = Math.GetRandomNumber(MultiplicationMax - MultiplicationMin + 1) - 1 + MultiplicationMin

    MulNumber2 = Math.GetRandomNumber(MultiplicationMax - MultiplicationMin + 1) - 1 + MultiplicationMin

 

    operation = Math.GetRandomNumber(5)

 

    'Creating 1 question depending on the random numbers

    If (operation = 1 Or operation = 4) Then

        File.AppendContents(filename, i + ") " + SubNumber1 + " - " + SubNumber2 + " =")

        File.AppendContents(filename, "")

        File.AppendContents(filename, "")

    EndIf

 

    'Creating 1 question depending on the random numbers

    If (operation = 2 Or operation = 5) Then 

        File.AppendContents(filename, i + ") " + AddNumber1 + " + " + AddNumber2 + " =")

        File.AppendContents(filename, "")

        File.AppendContents(filename, "")

    EndIf

 

    'Creating 1 question depending on the random numbers

    If operation = 3 Then

        File.AppendContents(filename, i + ") " + MulNumber1 + " * " + MulNumber2 + " =")

        File.AppendContents(filename, "")

        File.AppendContents(filename, "")

    EndIf

EndFor

'End of loop

 

 

So, the flow is pretty straightforward.

The program loops for 20 times, and each time will generate two numbers (operators) and an operator. And write the output to a file with today's timestamp. For now, he will need to change the Date variable everyday.

He needed a bit of help with outputting to a file, so I helped him a bit. I didn't know how to do it myself and had to look it up. Since I was pressed for time, so it may not be the most ideal way of doing it. But do notice the difference between File.WriteContents() and File.AppendContents(). Once I showed him once, he was able to reuse it throughout the program. That's one thing good with kids. Sometimes they can just do things without fully understanding why.

 

So, here are some changes from V1 that I can recall. Mostly it stemmed from the fact that he thought the program (specifically the random function wasn't being fair to him) and generated a lot more multiplication problems that its fair share. For example, one time he got like 9 questions out of 20 that are multiplication. He understood he should be between 6 and 7. I tried to explain him that it's a probability thing, so no guarantee of anything. Plus the random function in Small Basic (in fact in any programming language/library) is a pseudo random function, which is probably too much info for him.

 

But I do realize that some 2-digit by 2-digit multiplication (e.g., 78*89) might be too hard to do in head, so I allowed him to set the maximum numbers for the two operators for multiplications to less than 60. Further, I allowed him to create addition and subtraction problems at twice the frequencies than that for multiplication. For the first part, it made the program more interesting since he had to #1 breaking out the operators, #2 introducing various variables for that. For the second part, he had the idea of using the random function to get a number between 1 and 5 (as opposed to between 1 and 3 in V1) and assign the operations accordingly. Frankly, that's probably the easiest way and how I would do it.

One thing is interesting is that he chose 1 and 4 for subtraction, 2 and 5 for addition, and 3 for multiplication. He thought that will bring the most luck to him (meaning potentially the least amount of multiplication problems.) He could be right. I don't know. You never know how the random function works.

 

So, this is the worksheet that's generated for today.

 

 

Math Practice for 2014-04-29

 

1) 94 - 56 =

 

2) 63 + 48 =

 

3) 96 + 42 =

 

4) 57 + 54 =

 

5) 93 + 88 =

 

6) 39 - 42 =

 

7) 72 - 85 =

 

8) 53 * 45 =

 

9) 27 * 48 =

 

10) 60 + 51 =

 

11) 24 - 79 =

 

12) 75 - 52 =

 

13) 29 + 56 =

 

14) 11 * 16 =

 

15) 43 + 24 =

 

16) 25 + 28 =

 

17) 95 - 79 =

 

18) 95 + 74 =

 

19) 38 * 18 =

 

20) 26 * 25 =

 

Happy mathing and small basicing :)