# Arup Guha
# 2/13/2020
# Solution to COP 2930 Individual Program #3B: Multiplication Training

import random

def main():

    # Greeting
    print("Welcome to the multiplication training program!")

    # Safe initial values
    rounds = 0
    curPerc = 100

    # Accumulator variables over rounds.
    totalQs = 0
    totalCorrect = 0
    
    # When we continue playing.
    while rounds < 5 and curPerc >= 90:

        # Will keep track of how many problems are correctly solved.
        correct = 0

        # Adding to total questions posed.
        totalQs += 10

        # Round greeting.
        print("Welcome to round", rounds+1)

        # Ask 10 questions.
        for i in range(10):

            # Generate question and correct answer.
            x = random.randint(1, 10)
            y = random.randint(1, 10)
            ans = x*y

            # Ask the user the problem and read in the answer.
            userAns = int(input("What is "+str(x)+" x "+str(y)+"?\n"))

            # Got it correct.
            if userAns == ans:
                correct += 1
                print("Great job, you got it!")

            # Incorrect response.
            else:
                print("Sorry, that is incorrect.",x,"x",y,"=",ans)

        # Calculate current percentage, which for 10 questions is always an int.
        curPerc = 10*correct

        # Update accumulators for all the rounds.
        totalQs += 10
        totalCorrect += correct

        # Print out round message.
        print("You solved",curPerc,"percentage of problems correctly in round",rounds+1)
        rounds += 1

    # If the current percentage is 90 or higher, then we passed the last round, so this must be adjusted.
    if curPerc >= 90:
        rounds += 1

    print("Congrats, you are at level ",rounds,".", sep="")
    
# Run it!
main()
