I am trying to create a function where it takes two parameters, an integer "flag" and a positive integer "n". If flag is 0, primary_school_quiz helps practice subtraction then generates n math problems that a pupil must answer in turn. For each question, it generates two random positive, single-digit numbers and asks the pupil for the answer to the math problem with those two numbers ( subtract the second number from the first) then prompts the pupil for the answer, and checks if her answer is correct. At the end of n questions, another function returns the number of questions answered correctly.
So far I have:
>>> primary_school_quiz(0,2)
Question 1:
What is the result of 3-10? -7
Question 2:
What is the result of 10-7? 3
2
I don't know how to execute the problem
Because the above returns:
Question0 What is the result of 8-5? 3
'3'
So far I have:
def primary_school_quiz(flag, n): if flag == 0: n1=(randint(0,9)) n2=(randint(0,9)) for i in range (n): q=input('Question'+str(i)+'What is the result of '+str(n1)+'-'+str(n2)+'?') return qThe output is supposed to look like:
>>> primary_school_quiz(0,2)
Question 1:
What is the result of 3-10? -7
Question 2:
What is the result of 10-7? 3
2
I don't know how to execute the problem
if flag == 0: n1= random.randint(0,9) n2= random.randint(0,9) for i in range (n): q=input('Question'+str(i)+'What is the result of '+str(n1)+'-'+str(n2)+'? ') return qHow would I make more than I question? And for the question to start at number 1?
Because the above returns:
Question0 What is the result of 8-5? 3
'3'