<div class="gmail_quote">On Fri, Sep 23, 2011 at 2:25 PM, ADRIAN KELLY <span dir="ltr">&lt;<a href="mailto:kellyadrian@hotmail.com">kellyadrian@hotmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">





<div><div dir="ltr">&lt;snip&gt; </div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div dir="ltr">can anyone explain the <strong><u>tries</u></strong> part of this programme to me i know its meant to count the number of guesses made by the user by adding 1 but i just cant figure out how it does this..........can someone explain??  i.e. tries = 1, tries +1 etc.... cant get my head around it...</div>

</div></blockquote><div><br></div><div>The concept that&#39;s confusing you here is something called order of evaluation, or evaluation strategy: <a href="http://en.wikipedia.org/wiki/Evaluation_strategy">http://en.wikipedia.org/wiki/Evaluation_strategy</a> </div>

<div><br></div><div>The best way to understand these things is to try it out, and the interactive interpreter is extremely handy.</div><div><br></div><div>I presume you understand the concept of assignment, correct? For example:</div>

<div><br></div><div>&gt;&gt;&gt; tries = 1 </div><div><br></div><div>Now tries contains 1:</div><div><br></div><div><div>&gt;&gt;&gt; tries = 1</div><div>&gt;&gt;&gt; tries</div><div>1</div></div><div><br></div><div>The variable &#39;tries&#39; now contains the value 1 (In Python this is not technically true, but it&#39;s useful to describe it that way).</div>

<div><br></div><div>&gt;&gt;&gt; tries = 4</div><div><br></div><div>Now &#39;tries&#39; contains 4. Of course, just like your standard algebra variables, you can use your variables in python:</div><div><br></div><div>&gt;&gt;&gt; tries * 4</div>

<div>16</div><div>&gt;&gt;&gt; tries + tries</div><div>8</div><div>&gt;&gt;&gt; tries / 1</div><div>4</div><div><br></div><div>when these expressions are /evaluated/ they produce the mathematical expression you probably expect. But you can do more than just evaluate expressions, you can store their results:</div>

<div><br></div><div>&gt;&gt;&gt; lots_of_tries = tries * 100</div><div>&gt;&gt;&gt; lots_of_tries</div><div>400</div><div><br></div><div>So what about the expression that confuses you?</div><div><br></div><div>&gt;&gt;&gt; tries = tries + 1</div>

<div>&gt;&gt;&gt; tries</div><div>5</div><div><br></div><div>Well, the first thing that happens when python sees the equals sign is that the right hand side of the expression is evaluated, so python takes:</div><div><br>
</div>
<div>    tries = tries + 1</div><div><br></div><div>and turns it into</div><div><br></div><div>    tries = 4 + 1</div><div>    tries = 5</div><div><br></div><div>So each time your program sees &#39;tries = tries + 1&#39; python evaluates the right side first, then assigns its value to the variable on the left.</div>

<div><br></div><div>HTH,</div><div>Wayne</div></div>