Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function output
#1
I created a math question generator and I was wondering how do I make the function return the number of questions answered correctly?

For example (on line 6),
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
This is my code:

quiz(flag, n):
    if flag == 0:
        for i in range (1,n+1):
            n1= random.randint(0,9)
            n2= random.randint(0,9)
            x= input('Question '+str(i)+':'+'\n'+'What is the result of '+str(n1)+'-'+str(n2)+'? ')
    elif flag == 1:
        for i in range (1,n+1):
            n1= random.randint(0,9)
            n2= random.randint(0,9)
            x= input('Question '+str(i)+':'+'\n'+'What is the result of '+str(n1)+'^'+str(n2)+'? ')
        
Reply
#2
first add code to determine if you have a correct answer, which you haven't done yet.
Then have a variable, initially set to 0,
and increment each time a correct answer is made.
display the counter wherever you wish
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  The "in" function, weird output extricate 3 2,050 Jun-07-2020, 05:28 AM
Last Post: extricate
  Problem with function output slyfox 1 1,451 Nov-27-2019, 07:01 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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