I'm a beginner in a computer science 1 class. We're learning to code with python. I've been asked to develop code for a simple math quiz. However, my code will no run and I receive the RESTART but no further output. Please advise.

import random

def add(num1, num2):
total_correct = 0

for I in range(2):

num1 = random.randint(1,20)
num2 = random.randint(1,20)
print(num1, "+", num2, '=', end = "")
answer = int(input())

if answer == (num1 + num2):
print("correct")
total_correct+=1
else:
print("incorrect")
return total_correct

def sub(num1, num2):
total_correct = 0

for I in range(2):

num1 = random.randint(1,20)
num2 = random.randint(1,20)
print(num1, "-", num2, "=", end = "")
answer = int(input())

if answer == (num1 - num2):
print("correct")
total_correct+=1
else:
print("incorrect")
return total_correct

def mult(num1, num2):
total_correct = 0

for I in range(2):
num1 = random.randint(1, 20)
num2 = random.randint(1,20)
print(num1, "*", num2, "=", end = "")
answer = int(input())

if answer == (num1*num2):
print("correct")
else:
print("incorrect")
return total_correct

def div(num1, num2):
total_correct = 0

for I in range(2):
num1 = random.randint(1,20)
num2 = random.randint(1,20)
print(num1, "//", num2, "=", end = "")
answer = int(input())

if answer == (num1//num2):
print("correct")
total_correct+=1
else:
print("incorrect")
return total_correct

def mod(num1,num2):

total_correct = 0

for I in range(2):
num1 = random.randint(1,20)
num2 = random.randint(1,20)
print(num1, "%", num2, "=", end = "")
answer = int(input())

if answer == (num1%num2):
print("correct")
else:
print("incorrect")
return total_correct

again = input()

while again == "yes":
correct_answers=0
correct_answers += add() + sub() + mult() + div() + mod()
print("You've completed the quiz, with a score of", correct_answers, "would you like to try again?", "Type yes to take the quiz again")
again = input()

Respuesta :

Answer:

1. Your program starts by asking for input, so you would need to type "yes" to begin. If you change your first

   again = input()

line to

   again = "yes"

then the while loop will start.

2. Your functions like add(), sub(), etc are defined to expect two parameters (num1, num2) but in your line that's adding correct_answers, you're calling them with no parameters. Since your functions are setting the values themselves, you can remove the parameters from the function definitions.

Explanation: