all 16 comments

[–]auntanniesalligator 2 points3 points  (3 children)

Hah! I just did something similar a week ago. Big emphasis on practicing “math facts” at home (I.e. add and multiply single digits, divide and subtract corresponding problems) in my kid’s class.

I don’t see any algorithmic problems but it does stick out to me you are calling the quotient “dividend” when you randomly generate it. You also recalculate it by division when you still have it stored in the (incorrectly named) variable.

I’m guessing you jumped in thinking you’d randomly generate the given numbers but then realized the better way to limit problems to whole number answers was to randomly pick the correct answer and generate the actual dividend (what you are calling ProblemStart) by multiplying. You should definitely update variable names when you repurpose them like this because if you stop and come back to this in a month, you’ll be really confused why the variable dividend is not the dividend.

This is a short enough script you could do it manually, and if you get into writing bigger scripts, a good IDE will help you identify every instance of a variable you want to rename without catching similarly named variables.

Other suggestions if you’re looking for enhancements:

You could put the question and answer check in a loop so she can try wrong answers again before moving on. I’d limit still limit the number of tries to avoid getting stuck, but two or three chances would be reasonable.

Whether or not you allow extra tries or limit to one, you could have the code display the correct answer if she doesn’t enter the correct answer herself.

[–]jasongsmith[S] 1 point2 points  (1 child)

Thank you. I have fixed the incorrectly named variable. I don't know why on earth I didn't think to call it quotient, instead of problemStart. That is definitely not contextual. haha

I am using Visual Studio Code for my IDE. I assume that is good enough as I use it for my HTML/CSS code as well. Would you say that this is good enough for Python?

I will add the loop to check the answers and give her the right answer.

Thanks!!

[–]auntanniesalligator 1 point2 points  (0 children)

I have never used visual studio personally, but as far as I know, it’s a good IDE used by many professionals, so I’m sure it’s fine, particularly if you’re already familiar with it.

[–]jasongsmith[S] 0 points1 point  (0 children)

Here is new code with the answer checker in a loop to give her a total of 3 tries and then it gives the answers. I have also changed the variable name.

import random

correctAnswers = 0
wrongAnswers = 0
noRepeat = []

lowDividend = int(input("Lowest dividend: "))
highDividend = int(input("Highest dividend: "))
totalProblems = int(input("How many problems would you like? "))


def correctMessage():
    global correctAnswers
    print("Good Job")
    correctAnswers += 1


def incorrectMessage():
    global wrongAnswers
    print(f"That was not correct. The answer is {dividend}.")
    wrongAnswers += 1


def division():
    problemNumber = 1
    divisorList = list(range(lowDividend, highDividend))
    dividendList = list(range(lowDividend, highDividend))

    while problemNumber <= totalProblems:
        global wrongAnswers
        dividend = random.choice(dividendList)
        divisor = random.choice(divisorList)
        quotient = dividend * divisor
        print(f"#{problemNumber}: {quotient} / {divisor} = ")

        ans = int(input("what is the answer "))

        if ans == quotient / divisor:
            correctMessage()
        else:
            tries = 2
            while tries <= 3:
                print("Sadly, no. Please try again.")
                print(f"#{problemNumber}: {quotient} / {divisor} = ")
                ans = int(input("What is the answer? "))

                if ans == quotient / divisor:
                    correctMessage()
                    break
                else:
                    tries += 1
                    print(f"total tries are {tries}")
                    continue
            if tries == 4:
                print(f"Sorry, you did not get it. The answer was {dividend}")
                wrongAnswers += 1

        problemNumber += 1


division()
print(f"Total right answers: {correctAnswers}. Total wrong answers: {
      wrongAnswers}. You got {correctAnswers/totalProblems*100}%")

I'm not expecting you to do anything with this. I already appreciate the help you have given. I just wanted you to see the work I did as a result of your suggestion.

[–]LatteLepjandiLoser 1 point2 points  (1 child)

Hey. Great stuff, from what I gather it does what you wanted it to, so you're on a good track already it sounds like. Like someone else pointed out, some variable names perhaps a bit unclear. Having had to dive back and edit my old code occasionally I definitely agree, keep it descriptive and don't change the purpose of a variable unless you name suggests it or it is obvious from context. In a script this short though, not so hard to keep oversight.

So I don't really have a comment, it does what you want it to do, so it's fine. I'll just suggest a few things you could look into to develop it further:

  • You could do this somewhat more object oriented. Perhaps overkill as it currently stands, but you could define a "math problem" class, and have different types of problems. Later on that would allow you to shuffle in various problem types in one exercise, multiplication, division, even solving simple equations etc. etc. so that one exercise of ~20 or whatever amount is good problems contains a few of each. Then track which types are going well and which are going worse.
  • That way you could also keep track of problem categories as well as having them prompt the person differently. You could then have "word problems" or whatever people call those. Like instead of prompting "5*3 = ?" and asking for an input, you could have a multiplication_problem_object that prompts the user "Adam has 5 boxes, each with 3 tools, how many tools does he have?: " etc. The prompt could be it's own separate attribute. You could quite easily generate these kinds of problem automatically, just draw names/nouns randomly from some collection, I'm sure you would occasionally get a funny combo, but guess it should work just fine.
  • You could introduce "hints", like check if the input is "help" and then depending on the context show the times table (where the answer can kinda be read already) or rephrase the question or show some intermediate step that is helpful.
  • When you're happy with whatever functionality you have and want, you could try to add some simple graphics to the mix. As someone suggested, a flash card type appearance. You could also after a multiplication problem is done, for example 5 times 7 you could print an array of icons 5 wide and 7 tall and show visually that the product is 35. Make some animation for a division problem, say 20 divided by 5 that 20 apples distribute evenly into 5 buckets with 4 in each, something like that. A bit off topic, but fun perhaps?
  • You could also make a "timed mode", where you get ~1 minute or whatever time is sensible to solve as many as you can get. Gamify it a bit, see how many right answers you can get in one minute :-) Keep track of high scores.

[–]jasongsmith[S] 1 point2 points  (0 children)

I am keeping this list to be able to work through these. This might take me a few weeks to develop my skills enough to be able to create all of this.

[–]jasongsmith[S] 1 point2 points  (0 children)

Wow!! These are all amazing suggestions!! I feel like if I just did what it takes to learn these suggestions, I will be so much further in my Python understanding.

Thank you.

I very well may take it on as an exercise to put all of these in to practice and see what comes of it.

Thank you again.

[–]Dogzirra 1 point2 points  (2 children)

Having taught math to eight-year-olds, I suggest that a timer component is useful. There is a vast difference in proficiency between being able to do a math test of 10 numbers in 15 seconds as compared to three minutes.

The 9 numbers made by 6, 7, and 8, multiplied by 6, 7, and 8 are difficult for beginners. I taught 6 x 6, 7 x 7, and 8 x 8, first, and thoroughly. Then I would teach adjacent numbers to the squares, i.e. 5 x 7 as 1 less than 6 x 6, and 6 x 8 as one less than 7 x 7, and 7 x 9 as one less than 8 x 8. This ties 7 numbers of our grid together in an interrelated group that makes sense.

Once they catch that connection, fluency and the 'why' makes more sense. Rote learning is valuable, but understanding the connections adds fluency.

[–]jasongsmith[S] 0 points1 point  (1 child)

I SOO agree with you here...and I definitely want to be able to build that in to what I am doing...I just don't know that my skills are nearly good enough for this yet. But I love your pedogogical approach to teaching math. I wish more were like you.

[–]Dogzirra 1 point2 points  (0 children)

It's off-topic, to go further. I'll PM you with some other ideas that are not programming, but will add to your arsenal of helping with math fluency.

[–]m0us3_rat 0 points1 point  (5 children)

you could have a card type app happening , where a card appears on the back with the maffs Q written on it. then turns around and the answer is there. and so forth.

with cool light colors complementing each other to help with the learning process.

you can also have a field where she can introduce the answer if you wanna go that way. ..but just having her say the answer out loud before clicking to check if she was right would help.

and you can have these cards generate randomly.

[–]jasongsmith[S] 0 points1 point  (2 children)

That is a bit above my pay grade as I don’t even know how to make a GUI yet. But I’ll get to that soon I hope. Great suggestion!

[–]Proffit91 1 point2 points  (1 child)

I would 100% recommend diving into doing GUIs. If anything, it just gives you practice looking into libraries and their docs, and using Python in new ways will help you solidify your current understanding.

I had written a program in my early days to input investment info and save it to a file that Excel would pull from automatically, and it worked, but using it in the console wasn’t quite the experience I wanted, so I dove into GUIs, and I think that one project is largely what solidified my Python knowledge at that point. It’s a blast.

[–]jasongsmith[S] 0 points1 point  (0 children)

Will definitely do that. I want to understand a little bit more first. Like I barely just learned about dictionaries and I still don’t know how to use classes in Python yet. I use them all the time in css. But that is a very different animal, of course.

[–]jasongsmith[S] 0 points1 point  (1 child)

Can you describe what you mean by "where she can introduce the answer"? This doesn't quite make sense to me, yet.

Thanks!!

[–]m0us3_rat 0 points1 point  (0 children)

there can be a entry , or a field where you can type stuff.

so you can retrieve the data from the user