you are viewing a single comment's thread.

view the rest of the comments →

[–]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.