Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following program runs a math quiz consisting of 10 multiplication problems

ID: 663529 • Letter: T

Question

The following program runs a math quiz consisting of 10 multiplication problems involving operands between 1 and 10:

import random

correct = 0

for i in range(10):
    num1 = random.randint(1, 10)
    num2 = random.randint(1, 10)
    prod = num1 * num2

    ans = int(raw_input("What is " + str(num1) + " times " + str(num2) + "? "))

    if ans == prod:
        print "That's right -- well done. "
        correct += 1
    else:
        print "No, I'm afraid the answer is ", prod, " "

print " I asked you 10 questions. You got ", correct, " of them right."
print "Well done!"


Please help me do the following:

Modify the program so that the user can choose how many questions they will be asked. Dont allow them to choose 0 or a negative number.

Add levels to the program:
o   Beginner - with operands between 1 and 10
o   Intermediate - with operands between 1 and 25
o   Advanced - with operands between 1 and 50
o   The user should choose the level when starting a quiz.

Modify the message at the end so that it says:
o   Well done! if the user answered more than 3/4 of the questions correctly.
o   You need more practice if they get between 1/2 and 3/4 of the questions correct.
o   Please ask your math teacher for help! if they get less than 1/2 of the questions correct.
(Round up if in doubt the user needs to answer 5 questions to get of 6 correct)

Allow the user to start another quiz without restarting the program.

Let the user choose the question type: addition, subtraction, multiplication, or mixed (randomly choose for each question).

Explanation / Answer

To satisfy all the conditions mentioned in the program many conditions and loops are required. Hence, I have seperated them with braces.

import random

{

correct=0

level=0

questions=0

restart=0

type=0

Start:

{

print"Enter the number of the level you wish to answer"

print"Enter 1 for Beginner"

print"Enter 2 for Intermediate"

print"Enter 3 for advanced"

level = int(raw_input(Please enter!!))

if level == 1:

{

print"You have chosen beginner level. Good Luck!!"

questions=int(raw_input("Enter the number of questions you wish to answer"))

if questions <= 0:

print("Choose a valid number of questions!")

else:

{

print("Enter the number for type of questions you wish to answer:")

type = int(raw_input(print"1.Addition" "2.Subtraction" "3.Multiplication" "4.Mixed"))

correct = 0

if type == 1:

{

for i in range(questions):

{
    num1 = random.randint(1, 10)
    num2 = random.randint(1, 10)
sum = num1 + num2

    ans = int(raw_input("What is " + str(num1) + " + " + str(num2) + "? "))

    if ans == sum:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", sum " "

}

if correct >= floor(3/4*questions):

print"Well Done!!"

else if correct < floor(3/4*questions) && correct > floor(1/2*questions):

print"More practice required!"

else

print"Please ask your math teacher for help!"

}

else if type == 2:

{

for i in range(questions):

{
    num1 = random.randint(1, 10)
    num2 = random.randint(1, 10)
diff = num1 - num2

    ans = int(raw_input("What is " + str(num1) + " - " + str(num2) + "? "))

    if ans == diff:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", diff " "

}

if correct >= floor(3/4*questions):

print"Well Done!!"

else if correct < floor(3/4*questions) && correct > floor(1/2*questions):

print"More practice required!"

else

print"Please ask your math teacher for help!"

}

else if type == 3:

{

correct = 0

for i in range(questions):

{
    num1 = random.randint(1, 10)
    num2 = random.randint(1, 10)
    prod = num1 * num2

    ans = int(raw_input("What is " + str(num1) + " times " + str(num2) + "? "))

    if ans == prod:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", prod, " "

}

if correct >= floor(3/4*questions):

print"Well Done!!"

else if correct < floor(3/4*questions) && correct > floor(1/2*questions):

print"More practice required!"

else

print"Please ask your math teacher for help!"

}

else if type == 4:

{

correct =0;

for i in range(questions)

{

n=random(1,3)

if n==1:

{

    num1 = random.randint(1, 10)
    num2 = random.randint(1, 10)
sum = num1 + num2

    ans = int(raw_input("What is " + str(num1) + " + " + str(num2) + "? "))

    if ans == sum:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", sum " "

}

else if n==2:

{

    num1 = random.randint(1, 10)
    num2 = random.randint(1, 10)
diff = num1 - num2

    ans = int(raw_input("What is " + str(num1) + " - " + str(num2) + "? "))

    if ans == diff:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", diff " "

}

else if n==3:

{

num1 = random.randint(1, 10)
    num2 = random.randint(1, 10)
    prod = num1 * num2

    ans = int(raw_input("What is " + str(num1) + " times " + str(num2) + "? "))

    if ans == prod:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", prod, " "

}

}

if correct >= floor(3/4*questions):

print"Well Done!!"

else if correct < floor(3/4*questions) && correct > floor(1/2*questions):

print"More practice required!"

else

print"Please ask your math teacher for help!"

}

}

Else if level == 2:

{

print"You have chosen intermediate level. Good Luck!!"

questions=int(raw_input("Enter the number of questions you wish to answer"))

if questions <= 0:

print("Choose a valid number of questions!")

else:

{

print("Enter the number for type of questions you wish to answer:")

type = int(raw_input(print"1.Addition" "2.Subtraction" "3.Multiplication" "4.Mixed"))

correct = 0

if type == 1:

{

for i in range(questions):

{
    num1 = random.randint(1, 25)
    num2 = random.randint(1, 25)
sum = num1 + num2

    ans = int(raw_input("What is " + str(num1) + " + " + str(num2) + "? "))

    if ans == sum:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", sum " "

}

if correct >= floor(3/4*questions):

print"Well Done!!"

else if correct < floor(3/4*questions) && correct > floor(1/2*questions):

print"More practice required!"

else

print"Please ask your math teacher for help!"

}

else if type == 2:

{

for i in range(questions):

{
    num1 = random.randint(1, 25)
    num2 = random.randint(1, 25)
diff = num1 - num2

    ans = int(raw_input("What is " + str(num1) + " - " + str(num2) + "? "))

    if ans == diff:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", diff " "

}

if correct >= floor(3/4*questions):

print"Well Done!!"

else if correct < floor(3/4*questions) && correct > floor(1/2*questions):

print"More practice required!"

else

print"Please ask your math teacher for help!"

}

else if type == 3:

{

correct = 0

for i in range(questions):

{
    num1 = random.randint(1, 25)
    num2 = random.randint(1, 25)
    prod = num1 * num2

    ans = int(raw_input("What is " + str(num1) + " times " + str(num2) + "? "))

    if ans == prod:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", prod, " "

}

if correct >= floor(3/4*questions):

print"Well Done!!"

else if correct < floor(3/4*questions) && correct > floor(1/2*questions):

print"More practice required!"

else

print"Please ask your math teacher for help!"

}

else if type == 4:

{

correct =0;

for i in range(questions)

{

n=random(1,3)

if n==1:

{

    num1 = random.randint(1, 25)
    num2 = random.randint(1,25)
sum = num1 + num2

    ans = int(raw_input("What is " + str(num1) + " + " + str(num2) + "? "))

    if ans == sum:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", sum " "

}

else if n==2:

{

    num1 = random.randint(1, 25)
    num2 = random.randint(1, 25)
diff = num1 - num2

    ans = int(raw_input("What is " + str(num1) + " - " + str(num2) + "? "))

    if ans == diff:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", diff " "

}

else if n==3:

{

num1 = random.randint(1, 25)
    num2 = random.randint(1, 25)
    prod = num1 * num2

    ans = int(raw_input("What is " + str(num1) + " times " + str(num2) + "? "))

    if ans == prod:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", prod, " "

}

}

if correct >= floor(3/4*questions):

print"Well Done!!"

else if correct < floor(3/4*questions) && correct > floor(1/2*questions):

print"More practice required!"

else

print"Please ask your math teacher for help!"

}

}

else if level == 3:

{

print"You have chosen advanced level. Good Luck!!"

questions=int(raw_input("Enter the number of questions you wish to answer"))

if questions <= 0:

print("Choose a valid number of questions!")

else:

{

print("Enter the number for type of questions you wish to answer:")

type = int(raw_input(print"1.Addition" "2.Subtraction" "3.Multiplication" "4.Mixed"))

correct = 0

if type == 1:

{

for i in range(questions):

{
    num1 = random.randint(1, 50)
    num2 = random.randint(1, 50)
sum = num1 + num2

    ans = int(raw_input("What is " + str(num1) + " + " + str(num2) + "? "))

    if ans == sum:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", sum " "

}

if correct >= floor(3/4*questions):

print"Well Done!!"

else if correct < floor(3/4*questions) && correct > floor(1/2*questions):

print"More practice required!"

else

print"Please ask your math teacher for help!"

}

else if type == 2:

{

for i in range(questions):

{
    num1 = random.randint(1, 50)
    num2 = random.randint(1, 50)
diff = num1 - num2

    ans = int(raw_input("What is " + str(num1) + " - " + str(num2) + "? "))

    if ans == diff:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", diff " "

}

if correct >= floor(3/4*questions):

print"Well Done!!"

else if correct < floor(3/4*questions) && correct > floor(1/2*questions):

print"More practice required!"

else

print"Please ask your math teacher for help!"

}

else if type == 3:

{

correct = 0

for i in range(questions):

{
    num1 = random.randint(1, 50)
    num2 = random.randint(1, 50)
    prod = num1 * num2

    ans = int(raw_input("What is " + str(num1) + " times " + str(num2) + "? "))

    if ans == prod:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", prod, " "

}

if correct >= floor(3/4*questions):

print"Well Done!!"

else if correct < floor(3/4*questions) && correct > floor(1/2*questions):

print"More practice required!"

else

print"Please ask your math teacher for help!"

}

else if type == 4:

{

correct =0;

for i in range(questions)

{

n=random(1,3)

if n==1:

{

    num1 = random.randint(1, 50)
    num2 = random.randint(1, 50)
sum = num1 + num2

    ans = int(raw_input("What is " + str(num1) + " + " + str(num2) + "? "))

    if ans == sum:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", sum " "

}

else if n==2:

{

    num1 = random.randint(1, 50)
    num2 = random.randint(1, 50)
diff = num1 - num2

    ans = int(raw_input("What is " + str(num1) + " - " + str(num2) + "? "))

    if ans == diff:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", diff " "

}

else if n==3:

{

num1 = random.randint(1, 50)
    num2 = random.randint(1, 50)
    prod = num1 * num2

    ans = int(raw_input("What is " + str(num1) + " times " + str(num2) + "? "))

    if ans == prod:

{
        print "That's right -- well done. "
        correct += 1

}
    else:
        print "No, I'm afraid the answer is ", prod, " "

}

}

if correct >= floor(3/4*questions):

print"Well Done!!"

else if correct < floor(3/4*questions) && correct > floor(1/2*questions):

print"More practice required!"

else

print"Please ask your math teacher for help!"

}

}

else:

print"Please chose a valid level."

}

restart = int(raw_input(print"Enter 1 if you wish to continue with another quiz:"))

if restart == 1:

goto Start

else:

exit

}