<p dir="auto">The state variable is named 'var', but it is referred as 'state' afterwards.<br>
Changing this:<br>
new_value = tf.add(<strong>state</strong>, one)<br>
update = tf.assign(<strong>state</strong>, new_value)<br>
To this:<br>
new_value = tf.add(<strong>var</strong>, one)<br>
update = tf.assign(<strong>var</strong>, new_value)<br>
Solves the problem.</p>
<p dir="auto">In <a href="http://tensorflow.org/get_started/basic_usage.md#variables" rel="nofollow">http://tensorflow.org/get_started/basic_usage.md#variables</a></p>
<p dir="auto">the variable in the example is initialized as <code class="notranslate">var</code>, then subsequently referred to as <code class="notranslate">state</code><br>
leading to an obvious NameError:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;./variables.py&quot;, line 8, in &lt;module&gt;
    new_value = tf.add(state, one)
NameError: name 'state' is not defined"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "./variables.py", line 8, in &lt;module&gt;
    new_value = tf.add(state, one)
NameError: name 'state' is not defined
</code></pre></div>