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>So python scope is defined by indents (as mentioned by the comment above). So any statement that creates a layer of scope is seperated by an indent. Examples include classes, functions, loops, and boolean statements. Here is an example of this.</p>

<pre><code>Class A:
    def __init__(self, msg):
        self.message = msg
    def print_msg(self):  # prints your message
        print self.message
    def is_hi(self):
        if self.message == "hi":
            return true
        else:
            return false
</code></pre>

<p>This shows the different layers of scope that can exist.
Your code is not working right now because you are defining a function and then putting nothing in its scope. You would have to put anything within the scope of the function for that error to go away but that is probably not what you are looking for.</p>

python