I'm half way through a chance fighting program and I wanted to shorten my work by using functions. But I got the error,  UnboundLocalError: local variable 'Ehealth' referenced before assignment    This is my code so far...  import random import sys import time  print ("You encounter a wild boar.")  time.sleep(1)  Weapon = input("Do you use a 'Bow and Arrow' or a 'Sword'.")  Ehealth = (100) health = (100) Ealive = (1) alive = (1)  def attack():     damage = (random.randrange(5,21))     time.sleep(3)      print ("You attack the Boar for " + str(damage) + " attack points.")     time.sleep(3)      Ehealth = (Ehealth - damage)      print ("The Boars health is at " + str(Ehealth) + ".")     time.sleep(3)  if Weapon == ("Bow and Arrow"):     Emiss = (20)    #out of 40     miss = (15)     #out of 40      Espeed = (random.randrange(1,11))     speed = (random.randrange(1,11))      if Espeed &gt; (speed):         print ("The Boar is faster than you so he attacks first.")         time.sleep(3)          print ("Your health is at " + str(health) + " and the Boars health is at " + str(Ehealth) + ".")         time.sleep(3)          while (alive == 1):      #1 = alive, 2 = dead             Emiss = (random.randrange(1,41))             if Emiss &lt; (20):                  print ("The Boar missed.")                  attack()                  if Ehealth &gt; (0):                     alive = (1)                      continue                  else:                     alive = (2)                     print ("You Won!")                      sys.exit()                Edamage = (random.randrange(5,16))              print ("The Boar attacks you with " + str(Edamage) + " attack points.")             time.sleep(4)              health = (health - Edamage)             time.sleep(4)              print ("Your health is at " + str(health) + ".")             time.sleep(4)              if alive &lt;= (0):                 print ("You died...")                 sys.exit()              attack()              if Ehealth &gt; (0):                 alive = (1)              else:                 alive = (2)                 print ("You Won!")                  sys.exit()   I got the error at the line on   Ehealth = (Ehealth - damage)   Any help would be appreciated.
The following code works as expected in both Python 2.5 and 3.0:  a, b, c = (1, 2, 3)  print(a, b, c)  def test():     print(a)     print(b)     print(c)    # (A)     #c+=1       # (B) test()   However, when I uncomment line (B), I get an UnboundLocalError: 'c' not assigned at line (A). The values of a and b are printed correctly. This has me completely baffled for two reasons:   Why is there a runtime error thrown at line (A) because of a later statement on line (B)? Why are variables a and b printed as expected, while c raises an error?   The only explanation I can come up with is that a local variable c is created by the assignment c+=1, which takes precedent over the "global" variable c even before the local variable is created. Of course, it doesn't make sense for a variable to "steal" scope before it exists.  Could someone please explain this behavior?
A triangle with vertices on the sides of a square, with one at a midpoint, cannot be equilateral What’s the difference between "Array()" and "[]" while declaring a JavaScript array? How to cluster time series? I have a question about cluster analysis. There are 3000 companies, which have to be clustered according to their power usage over 5 years. Each company has values for every hour during 5 years. I would like to find out if some companies have the same pattern in usage power over the time period. The results should be used for daily prediction of power usage. If you have some ideas how to cluster time series in SPSS, please share with me. If $f(xy)=f(x)f(y)$ then show that $f(x) = x^t$ for some t The difference between GPU and CPU I know what a CPU is(I think). It's the thing who's speed is measured in GigaHertz(these days).  However, you hear a lot about a GPU, and letting the GPU take over, not letting the CPU but the GPU do it, GPU-based rendering, etc...  What is this GPU anyway? How can I access it and use it to my advantage? What am I missing out on here? Floquet and Bloch's theorems : connection? It is often stated that  and  are equivalent, even the Bloch's theorem is often referred as Floquet-Bloch theorem.  However, it seems quite confusing to me since the former involves a second order differential equation (Schroedinger equation with a periodic potential) while the latter is defined for a first order one.  Can someone clarify this to me? Also it would be nice if I can get references that connect the two. how to create shortcode in wordpress So I have the following code:   &lt;span class="delete"&gt;&lt;a onclick="return confirm('Are you sure?');" href="&lt;?php echo wp_nonce_url( add_query_arg( array( 'action' =&gt; 'my-delete-product', 'product_id' =&gt; $post-&gt;ID ), my_get_navigation_url('products') ), 'my-delete-product' ); ?&gt;"&gt;&lt;?php _e( '삭제', 'my' ); ?&gt;&lt;/a&gt; | &lt;/span&gt;   It is a simple button.  I want to make this into a shortcode so that I can use it anywhere where appropriate.  Any suggestions?  Thanks. When we implement the Always Encrypted feature in SQL Server 2016, do the .mdf files, .ldf files and .bak files get encrypted as well?  I would like to know if the data/log/backup files gets encrypted or not. Show that $d_b(x,y)=\frac{d(x,y)}{1+d(x,y)}$ is a metric. where $(X,d)$ is a metric and $x,y \in X$.  I know we need to show:   non-negativity: $d(x,y)\geq$ 0 $d(x,y)=0$ if and only if $x=y$ symmetry: $d(x,y)=d(y,x)$ $d(x,z)\leq d(x,y) + d(y,z)$   I think we need to consider the derivative of $f(t)=\frac{t}{1+t}$ however I am not sure what to do next. I think the questions says it all! :)  By TeX, I mean any derivative of TeX as long as the code is clearly a derivative of TeX, i.e. that it could belong on TeX.SX (and not pure Lua for example).  I'll give two answers myself so you see what I mean. I´m trying to model a race track using a bezier curve, but, when I add modifiers -> array -> curve I get this :    What should I check for to get the mesh following the curve correctly ? Thankyou When I get an idea for something I'd like to make in Blender, I hit up Google for specifics, then blender SE when I get stuck.   I'm very overwhelmed by the immensity of Blender and I'm a little afraid that this self-directed approach is going to lead me to develop bad habits. Is there a "best practice" way of learning to use Blender? How to write permutations as product of disjoint cycles and transpositions $$\sigma=\begin{pmatrix} 1 &amp; 2 &amp;3 &amp; 4&amp; 5&amp; 6&amp;7 &amp;8 &amp;9 &amp;10 &amp; 11 \\ 4&amp;2&amp;9&amp;10&amp;6&amp;5&amp;11&amp;7&amp;8&amp;1&amp;3    \end{pmatrix}$$  (1) I am asked to write this permutation in $S_{11}$ as a product of disjoint cycles and also as a product of transpositions.   (2) Also find the order of the element. Is this permutation even or odd?  I think these are the disjoint cycles  $E_{1}=(1,4,10)$, $\;\operatorname{order}E_1 =3$  $E_{2}= (3,9,8,7,11),\;$ $\operatorname{order}E_{2} =5$  $E_{3}=(5,6),\;$ $\operatorname{order}E_{3} =2$  $S_{11}$=  $E_{1} \cdot E_{2}\cdot  E_{3}$  The order of $\operatorname{order}E_{3}$ is even so the order of the permutation is even. Why are they asking this? And what is the significance of it being even or odd?  Transpositions – I have read this a couple times but the one example in my textbook is rather unclear, I am not sure what this means?  I think the transposition for $E_{1}$ is $(1,4)(1,10)$ but I'm not sure what this means. Remove empty elements from an array in Javascript How do I remove empty elements from an array in JavaScript?   Is there a straightforward way, or do I need to loop through it and remove them manually? Erf as term for plot of land in a town or city. Is this word only used in southern Africa? The Free Dictionary website states and so does Wikipedia:     erf [ɜːf]   n pl erven [ˈɜːvən]   (Engineering / Civil Engineering) South African a plot of land, usually urban, marked off for building purposes   [Afrikaans]   The term erf is used in legal documentation and technical English throughout South Africa and Namibia, maybe even further afield in the region.  Is it used anywhere else, except maybe the Dutch/Flemish regions in Europe, where I assume the term originated?  An example:      The client purchased Erf 132, Windhoek for a large sum of money. He intends to build a house on this erf.   The capitalisation of "Erf 132" is commonplace, since it is a definition of a location. This is similar to capitalisation of towns or cities. I find it slightly awkward, but that is how it is done. I have some basic data on emission reductions and cost per car:  q24 &lt;- read.table(text = "reductions  cost.per.car     50  45     55  55     60  62     65  70     70  80     75  90     80  100     85  200     90  375     95  600     ",header = TRUE, sep = "")   I know that this is an exponential function, so I expect to be able to find a model that fits with:      model &lt;- nls(cost.per.car ~ a * exp(b * reductions) + c,           data = q24,           start = list(a=1, b=1, c=0))   but I'm getting an error:   Error in nlsModel(formula, mf, start, wts) :    singular gradient matrix at initial parameter estimates   I've read through  on the error I'm seeing and I'm gathering that the problem is probably that I need better/different start values (the initial parameter estimates makes a little more sense) but I'm not sure, given the data that I have, how I'd go about estimating better parameters. I assume that the following sentences are grammatically correct:   He resents your being more popular than he is. Most of the members paid their dues without my asking them. They objected to the youngest girl's being given the command position. What do you think about his buying such an expensive car? We were all sorry about Jane's losing her parents like that.   I'm still getting used to this possessive gerund structure. It sounded so weird to me at first. Is the structure used in both formal and informal contexts? Are there any alternative structures that result in the same meaning and are more frequently used? (Examples taken from ) Including section titles in fancyhf headers What was the first version of Ubuntu and where can I find it? lists Ubuntu 4.10 (Warty Warthog) as the first Ubuntu released by Canonical Ltd.  But I wanted to know whether there ever was an Ubuntu 1.x, as in Windows or Mac OS. If yes, is it available somewhere? Are there any research careers except professorship for a person holding PhD in pure mathematics?