Count how many times a variable is called
<p>I want to add something that will count how many times a variable is used (like variable <code>c</code>) and output in number of times variable <code>c</code> was used. What functions can I use? Here's the code:</p>

<pre><code>#! /usr/bin/python

question = raw_input
y = "Blah"
c = "Blahblahb"


print "Is bacon awesome"
if question() = "Yes":
    print y
else:
    print c

print "Blah"
if question() = "Yes":
    print y
else:
    print c
</code></pre>

<p>You could do this simply enough using an incrementing variable.</p>

<pre><code>counter = 0
# Event you want to track
counter += 1
</code></pre>

<p>Your Python 2.7 code, with a counter:</p>

<pre><code>question = raw_input
y = "Blah"
c = "Blahblahb"
counter = 0


print "Is bacon awesome"
if question() = "Yes":
    print y
else:
    print c
    counter += 1

print "Blah"
if question() = "Yes":
    print y
else:
    print c
    counter +=1

print counter
</code></pre>

python variables counting