# Arup Guha
# 3/8/2205
# Intro to Functions via Arithmetic Game

import random

def makeProblem(maxVal):

    # Make an empty list to store the numbers to add.
    problem = []

    # Return the numbers to add.
    for i in range(2):
        problem.append(random.randint(0, maxVal))

    # Return the list to the calling function.
    return problem

# Returns the largest operand that corresponds to the level, level.
def getMaxVal(level):
    if level == 1:
        return 5
    elif level == 2:
        return 10
    else:
        return 20

# Returns true if and only if the answer to the addition problem in problem is useranswer.
def isCorrect(problem, useranswer):

    # See if the numbers add up.
    if problem[0] + problem[1] == useranswer:
        return True

    # We get here if they didn't.
    return False

# Returns the percentage when someone gets correct questions out of numQ
def getCorrectPerc(correct, numQ):
    return 100*correct/numQ

# This will be my main function which runs the game.
def main():

    # Get how many questions the user wants to be asked.
    numQ = int(input("How many questions do you want?\n"))

    # Get the level the user wants.
    level = int(input("What level do you want(1,2 or 3)?\n"))

    # Get the largest number we'll do for the problems.
    myMaxVal = getMaxVal(level)

    correct = 0

    # Ask user the problems:
    for i in range(numQ):

        # Get the problem.
        myprob = makeProblem(myMaxVal)

        # Ask the user the problem, and get their answer.
        userAnswer = int(input("What is "+str(myprob[0])+" + "+str(myprob[1])+"?\n"))

        # Check if they got it correct.
        if isCorrect(myprob, userAnswer):
            correct += 1
            print("Great you got it correct!")

        # Incorrect case
        else:
            print("Sorry, you got it wrong, the correct answer is", myprob[0]+myprob[1])

    # Report the number correct.
    print("You got", getCorrectPerc(correct, numQ), "percent of the problems correct.")

# Calls main and runs the statements in main.
main()
