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>If I'm understanding your question correctly, you can try this:</p>

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


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

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

print "y was used " + str(y_counter) + " times!"
print "c was used " + str(c_counter) + " times!"
</code></pre>

python variables counting