function output - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: function output (/thread-5583.html) |
function output - student8 - Oct-12-2017 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 2This 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)+'? ') RE: function output - Larz60+ - Oct-12-2017 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 |