Python Forum
How to create a question generator?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create a question generator?
#1
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:
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 q 
The 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 q 
How 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'
Reply


Messages In This Thread
How to create a question generator? - by student8 - Oct-07-2017, 07:22 PM
RE: How to create a question generator? - by wavic - Oct-09-2017, 09:03 AM
RE: How to create a question generator? - by wavic - Oct-10-2017, 09:20 PM
RE: How to create a question generator? - by wavic - Oct-12-2017, 11:16 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020