Need quiz scoring function
<p>I have to create a basic 3 question quiz on farming. It needs to ask the 3 questions, output whether you got it correct or incorrect and if you got it incorrect you can try again. It also needs to have a score function.  I have completed the questions and the incorrect/correct part of the specification but no matter what I try I cannot get the score function to work. I have tried:</p>

<pre><code>score = 0

def counter(score)
    score = score + 1

def counter(score)
    score = 0
    score = score + 1

def counter(score)
    global score
    score = 0
    score = score + 1
</code></pre>

<p>and then following that once the answer was correct the line read :</p>

<pre><code>counter(score)
</code></pre>

<p>I have also tried</p>

<pre><code>score = 0
</code></pre>

<p>then</p>

<pre><code>score = score + 1
</code></pre>

<p>but nothing is working and I cannot figure out what is going wrong. It also needs to print how many the user got right at the end.</p>

<p>CODE:</p>

<pre><code>score = 0

def quiz():
    print("Here is a quiz to test your knowledge of farming...")
    print()
    print()
    print("Question 1")
    print("What percentage of the land is used for farming?")
    print()
    print("a. 25%")
    print("b. 50%")
    print("c. 75%")
    answer = input("Make your choice: ")
    if answer == "c":
       print("Correct!")
       score = score + 1
   else:
       print("Incorrect.")
       answer = input("Try again! ")
         if answer == "c":
            print("Correct")
            score = score + 1
         else:
             print("Incorrect! Sorry the answer was C.")
    print()
    print()
    print("Question 2")
    print("Roughly how much did farming contribute to the UK economy in 2014.")
    print()
    print("a. Â£8 Billion.")
    print("b. Â£10 Billion.")
    print("c. Â£12 Billion.")
    answer = input("Make your choice: ")
    if answer == "b":
       print("Correct!")
       score = score + 1
   else:
       print("Incorrect.")
       answer = input("Try again! ")
         if answer == "b":
            print("Ccrrect!")
            score = score + 1
         else:
            print("Incorrect! Sorry the answer was B.")
   print()
   print()
   print("Question 3.")
   print("This device, which was invented in 1882 has revolutionised farming. What is it called?")
   print()
   print("a. Tractor")
   print("b. Wagon.")
   print("c. Combine.")
   answer == input("Make your choice. ")
     if answer == "a":
         print("Correct!")
         score = score + 1
    else:
         print("Incorrect.")
         answer == input("Try again! ")
            if answer == "a":
               print("Correct!")
               score = score + 1
          else:
              print("Incorrect! Sorry the answer was A.")

print("You got {0}/3 right!".format(score))
</code></pre>

<p>A n00b (and working) way would be to do something like</p>

<pre><code>score = 0

def quiz():
    global score
</code></pre>

<p>The <code>global</code> keyword makes use of the global variable (which you declared <em>outside</em> your function <code>quiz</code>). Since you've not indented your code properly it's unclear if you're printing the last statement inside or outside the <code>quiz</code> function, but that doesn't matter. If you place both <code>score</code> and printing inside the quiz function or both outside you'll be fine. Good luck with homework!</p>

python