Math Tutor Program with Error Handling

numA = [4, 1, 6, 10, 2, 3, 7, 9, 11, 12, 5, 8]
numB = [2, 12, 10, 11, 1, 3, 7, 9, 4, 8, 5, 6]

choices = (“ADD”, “MULTIPLY”)

while True:
try:
choice = int(input(‘Enter: \n 1 for Adding\n 2 for Multiplying’))

    # Addition
    while choice == 1:
        # QUESTION 1

        print('Question 1:')
        print('Add ', numA[0], 'to ', numB[0])

        while True:
            try:
                add = int(input('What is the correct answer?'))
                add1 = numA[0] + numB[0]

                if add == add1:
                    print('CORRECT!!!\n')
                else:
                    print('WRONG!! The correct answer is: ', add1, '\n')
            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # QUESTION 2
        print('Question 2:')
        print('Add ', numA[1], 'to', numB[1])

        while True:
            try:
                add = int(input('What is the correct answer?'))
                add1 = numA[1] + numB[1]

                if add == add1:
                    print('CORRECT!!!\n')
                else:
                    print('WRONG!! The correct answer is: ', add1, '\n')
            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # QUESTION 3
        print('Question 3:')
        print('Add ', numA[2], 'to', numB[2])

        while True:
            try:
                add = int(input('What is the correct answer?'))
                add1 = numA[2] + numB[2]

                if add == add1:
                    print('CORRECT!!!\n')
                else:
                    print('WRONG!! The correct answer is: ', add1, '\n')
            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # QUESTION 4................................................
        print('Question 4:')
        print('Add ', numA[3], 'to', numB[3])

        while True:
            try:
                add = int(input('What is the correct answer?'))
                add1 = numA[3] + numB[3]

                if add == add1:
                    print('CORRECT!!!\n')
                else:
                    print('WRONG!! The correct answer is: ', add1, '\n')
            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # QUESTION 5...................................................
        print('Question 5:')
        print('Add ', numA[4], 'to', numB[4])

        while True:
            try:
                add = int(input('What is the correct answer?'))
                add1 = numA[4] + numB[4]

                if add == add1:
                    print('CORRECT!!!\n')
                else:
                    print('WRONG!! The correct answer is: ', add1, '\n')
            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # QUESTION 6...................................................
        print('Question 6:')
        print('Add ', numA[5], 'to', numB[5])

        while True:
            try:
                add = int(input('What is the correct answer?'))
                add1 = numA[5] + numB[5]

                if add == add1:
                    print('CORRECT!!!\n')
                else:
                    print('WRONG!! The correct answer is: ', add1, '\n')
            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # QUESTION 7..................................................
        print('Question 7:')
        print('Add ', numA[6], 'to', numB[6])

        while True:
            try:
                add = int(input('What is the correct answer?'))
                add1 = numA[6] + numB[6]

                if add == add1:
                    print('CORRECT!!!\n')
                else:
                    print('WRONG!! The correct answer is: ', add1, '\n')
            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # QUESTION 8,....................................................
        print('Question 8:')
        print('Add ', numA[7], 'to', numB[7])

        while True:
            try:
                add = int(input('What is the correct answer?'))
                add1 = numA[7] + numB[7]

                if add == add1:
                    print('CORRECT!!!\n')
                else:
                    print('WRONG!! The correct answer is: ', add1, '\n')
            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # QUESTION 9........................................................
        print('Question 9:')
        print('Add ', numA[8], 'to', numB[8])

        while True:
            try:
                add = int(input('What is the correct answer?'))
                add1 = numA[8] + numB[8]

                if add == add1:
                    print('CORRECT!!!\n')
                else:
                    print('WRONG!! The correct answer is: ', add1, '\n')
            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # QUESTION 10.........................................................
        print('Question 10:')
        print('Add ', numA[9], 'to', numB[9])

        while True:
            try:
                add = int(input('What is the correct answer?'))
                add1 = numA[9] + numB[9]

                if add == add1:
                    print('CORRECT!!!\n')
                else:
                    print('WRONG!! The correct answer is: ', add1, '\n')
            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # QUESTION 11.............................................................
        print('Question 11:')
        print('Add ', numA[10], 'to', numB[10])

        while True:
            try:
                add = int(input('What is the correct answer?'))
                add1 = numA[10] + numB[10]

                if add == add1:
                    print('CORRECT!!!\n')
                else:
                    print('WRONG!! The correct answer is: ', add1, '\n')
            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # QUESTION 12...............................................................
        print('Question 12:')
        print('Add ', numA[11], 'to', numB[11])

        while True:
            try:
                add = int(input('What is the correct answer?'))
                add1 = numA[11] + numB[11]

                if add == add1:
                    print('CORRECT!!!\n')
                else:
                    print('WRONG!! The correct answer is: ', add1, '\n')
            except Exception:
                print('Enter numbers only\n')
            else:
                break

    # Multiplication
    while choice == 2:

        # Question 1......................................................................
        print('Question 1:')
        print('Multiply', numA[0], 'with', numB[0])

        while True:
            try:
                multip = int(input('What is the correct answer?'))
                multip1 = numA[0] * numB [0]

                if multip == multip1:
                 print('CORRECT!!! \n')
                else:
                    print('WRONG!! The correct answer is: ', multip1, '\n')

            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # Question 2......................................................................
        print('Question 2:')
        print('Multiply', numA[1], 'with', numB[1])

        while True:
            try:
                multip = int(input('What is the correct answer?'))
                multip1 = numA[1] * numB [1]

                if multip == multip1:
                 print('CORRECT!!! \n')
                else:
                    print('WRONG!! The correct answer is: ', multip1, '\n')

            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # Question 3......................................................................
        print('Question 3:')
        print('Multiply', numA[2], 'with', numB[2])

        while True:
            try:
                multip = int(input('What is the correct answer?'))
                multip1 = numA[2] * numB [2]

                if multip == multip1:
                 print('CORRECT!!! \n')
                else:
                    print('WRONG!! The correct answer is: ', multip1, '\n')

            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # Question 4......................................................................
        print('Question 4:')
        print('Multiply', numA[3], 'with', numB[3])

        while True:
            try:
                multip = int(input('What is the correct answer?'))
                multip1 = numA[3] * numB [3]

                if multip == multip1:
                 print('CORRECT!!! \n')
                else:
                    print('WRONG!! The correct answer is: ', multip1, '\n')

            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # Question 5......................................................................
        print('Question 5:')
        print('Multiply', numA[4], 'with', numB[4])

        while True:
            try:
                multip = int(input('What is the correct answer?'))
                multip1 = numA[4] * numB [4]

                if multip == multip1:
                 print('CORRECT!!! \n')
                else:
                    print('WRONG!! The correct answer is: ', multip1, '\n')

            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # Question 6......................................................................
        print('Question 6:')
        print('Multiply', numA[5], 'with', numB[5])

        while True:
            try:
                multip = int(input('What is the correct answer?'))
                multip1 = numA[5] * numB [5]

                if multip == multip1:
                 print('CORRECT!!! \n')
                else:
                    print('WRONG!! The correct answer is: ', multip1, '\n')

            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # Question 7......................................................................
        print('Question 7:')
        print('Multiply', numA[6], 'with', numB[6])

        while True:
            try:
                multip = int(input('What is the correct answer?'))
                multip1 = numA[6] * numB [6]

                if multip == multip1:
                 print('CORRECT!!! \n')
                else:
                    print('WRONG!! The correct answer is: ', multip1, '\n')

            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # Question 8......................................................................
        print('Question 8:')
        print('Multiply', numA[7], 'with', numB[7])

        while True:
            try:
                multip = int(input('What is the correct answer?'))
                multip1 = numA[7] * numB [7]

                if multip == multip1:
                 print('CORRECT!!! \n')
                else:
                    print('WRONG!! The correct answer is: ', multip1, '\n')

            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # Question 9......................................................................
        print('Question 9:')
        print('Multiply', numA[8], 'with', numB[8])

        while True:
            try:
                multip = int(input('What is the correct answer?'))
                multip1 = numA[8] * numB [8]

                if multip == multip1:
                 print('CORRECT!!! \n')
                else:
                    print('WRONG!! The correct answer is: ', multip1, '\n')

            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # Question 10......................................................................
        print('Question 10:')
        print('Multiply', numA[9], 'with', numB[9])

        while True:
            try:
                multip = int(input('What is the correct answer?'))
                multip1 = numA[9] * numB [9]

                if multip == multip1:
                 print('CORRECT!!! \n')
                else:
                    print('WRONG!! The correct answer is: ', multip1, '\n')

            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # Question 11......................................................................
        print('Question 11:')
        print('Multiply', numA[10], 'with', numB[10])

        while True:
            try:
                multip = int(input('What is the correct answer?'))
                multip1 = numA[10] * numB [10]

                if multip == multip1:
                 print('CORRECT!!! \n')
                else:
                    print('WRONG!! The correct answer is: ', multip1, '\n')

            except Exception:
                print('Enter numbers only\n')
            else:
                break

        # Question 12......................................................................
        print('Question 12:')
        print('Multiply', numA[11], 'with', numB[11])

        while True:
            try:
                multip = int(input('What is the correct answer?'))
                multip1 = numA[11] * numB [11]

                if multip == multip1:
                 print('CORRECT!!! \n')
                else:
                    print('WRONG!! The correct answer is: ', multip1, '\n')

            except Exception:
                print('Enter numbers only\n')
            else:
                break

except Exception:
    print("Select either 1 or 2")

else:
    break

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *