# Arup Guha
# Multiplication Game with Functions
# 10/13/2020

import random

def main():

    random.seed()

    # Get the parameters for the game.
    numMult = int(input("How many problems do you want?\n"))
    maxVal = int(input("What is the max number in a problem?\n"))

    # Keep track of how many correct.
    correct = 0

    # Go through the problems
    for i in range(numMult):

        # Generate the problem.
        val1 = random.randint(1, maxVal)
        val2 = random.randint(1, maxVal)

        # Get their answer.
        ans = int(input("What is "+str(val1)+" x "+str(val2)+"?\n"))

        # If they got it, add to our accumulator.
        if isCorrect(val1, val2, ans):
            correct += 1 # correct = correct + 1
            print("Great, you got it!")

        # Give them the answer if they missed it.
        else:
            print("Sorry, that is incorrect. The answer was ",val1*val2,".", sep="")

    
    print("You got ",percCorrect(correct,numMult),"% of the problems correct.", sep="")

# Returns true iff num1 times num2 is userAnswer
def isCorrect(num1, num2, userAnswer):
    return num1*num2 == userAnswer

# Returns the percentage of problems solved correct out of total.
def percCorrect(correct, total):
    return int(correct/total*100 + .5)

# Run it!
main()
