I have a part of a bigger program here:  from random import randint  def computerChooses():     import random     choices = ["rock", "paper", "scissors"]     computerChoice = choices[randint(0,2)]     def whoWins():     if computerChoice == "rock":                 print("DO THIS")     elif computerChoice == "paper":                 print("DO THIS")     elif computerChoice == "scissors":                 print("DO THIS")  computerChooses() whoWins()   I always end up with:  NameError: name 'computerChoice' is not defined   (even though I believe it is!)  This, the error message states, is for line 20, and line 12.  What did  I do wrong and where, specifically?  Thanks, Khy
What exactly are the Python scoping rules?  If I have some code:  code1 class Foo:    code2    def spam.....       code3       for code4..:        code5        x()   Where is x found?  Some possible choices include the list below:   In the enclosing source file In the class namespace In the function definition In the for loop index variable Inside the for loop   Also there is the context during execution, when the function spam is passed somewhere else. And maybe  pass a bit differently?  There must be a simple reference or algorithm somewhere.  It's a confusing world for intermediate Python programmers.
Turn off paragraph indention for a single line Where can a tourist apply for a UK Visitor (standard) Visa? Does existence of $\gcd$ implies PID? We know that if $A$ is a PID, then we can guarantee the existence of a $\gcd$ between two elements. My question is, does the converse hold? If I know that every two elements have a $\gcd$, do I know that the ring is a PID? My intuition says no, in that case I would like a counter-example.  Thanks. Variance of product of multiple independent random variables Could there be a bit of reputation leakage between the sites, please? $AB-BA$ is a nilpotent matrix if it commutes with $A$ I saw this in a  and am putting it here for posterity.  Problem: Let $A$ and $B$ by square matrices and set $C=AB-BA$. If $AC=CA$, prove $C$ is nilpotent. Avoiding if statement inside a for loop? Can I run Ubuntu OS on a Android 4.0 tablet? I need to make a converter to go from RS422 full duplex to my Arduino. I have found lots of different chips which I think can do this, but am slightly confused by the terminology. The RS422 device is a laser distance sensor ().  It has RX+, RX-, TX+, TX-. So I have two lines for input and two lines for output.  I could use two RS485 line drivers to achieve the full duplex comms which I need.  There are a lot of chips to do that.  But then on my Arduino (clone: chipkit max32) would I need to use two UART channels? And then alternate which one I am sending each byte on?  The device uses 4 byte instructions. So if I wanted to send an instruction would I send Serial1(firstByte) then Serial2(secondByte), Serial1(thirdByte), Serial2(fourthByte)?   And then receive data the same way? I feel like I am missing something and can do this on one UART channel but am not sure how. '₴' is a currency sign used for the Ukrainian Hryvnia. It's in Unicode since 2004. I want to use it in spreadsheets as a sign for money values, but Google Spreadsheets doesn't understand it as a number if I add it after or before my value in the cell. How do I make Google Spreadsheets understand it's currency and display it as a number in my desired format? How can I take a self-portrait without using a remote?  My camera is a Canon Powershot SX210 IS. I do not have a remote, but I do have a tripod. Can the term "etymology" be applied to a phrase or only individual words? I have always heard the term used in referring to a single word. When browsing questions on this site, I've seen it used applied to entire phrases, and have suppressed the compulsion to edit them and replace the term with origin. If the $n^{th}$ partial sum of a series $\sum a_n$ is $S_n = \frac{n-1}{n+1}$, find $a_n$ and the sum. If the $n^{th}$ partial sum of a series $\sum a_n$ is $S_n = \dfrac{n-1}{n+1}$, find $a_n$ and the sum.  By definition,  the sum of the series is the $\lim n\to\infty$ of it's $n^{th}$ partial sum.  $$\text{ Sum = } \lim_{n\to\infty} = \dfrac{n-1}{n+1} = 1$$  I am asked to find $a_n$. How do I do this? What is the procedure? Proving bessel identity $[J_0(x)]^2 + 2[J_1(x)]^2 + 2[J_2(x)]^2 + \cdots = 1$ and $|J_0(x)|\le 1$ The generating function for a Bessel equation is:      $$g(x,t) = e^{(x/2)(t-1/t))}$$      Using the product $g(x,t)\cdot g(x,-t)$ show that:      a) $$[J_0(x)]^2 + 2[J_1(x)]^2 + 2[J_2(x)]^2 + \cdots = 1$$      and consequently:      b)      $$|J_0(x)|\le 1, \forall x$$      c) $$|J_n(x)| \le \frac{1}{\sqrt{2}}; n=1,2,3,\cdots$$   For a) I tried the product:  $$e^{(x/2)(t-1/t))}\cdot e^{(x/2)(-t+1/t))} = 1$$  I at least arrived at the right side of the equation. Since this generates the bessel functions, I should arrive at something related to $J_n$ in the left side. I know that  $$e^{(x/2)(t-1/t))} = \sum_{n=0\infty}^{\infty} J_n(x)t^n$$  $$e^{(x/2)(-t+1/t))} = \sum_{n=0\infty}^{\infty} J_n(x)(-t)^n$$  but it's not just a matter of multiplying coefficients from the two infinite series, right?  For $b$, I tried to use  but it's not as obvious  I have no idea how to deal with $c$, could somebody help me? Display current layout (language code/country flag) in keyboard indicator Just upgraded from 10.04 to 10.10, and the keyboard indicator applet no longer displays the two-letter country code for the active layout.  This is terrible. Is this the default behaviour? Anyone using two layouts can't tell which language they're in.  I can't seem to find the setting for this, it used to be in the preferences for keyboard layout.  Update 1: In case this wasn't obvious - I have two keyboard layouts - English and Hebrew. I just upgraded form 10.04, where the country code (USA/IL) was displayed, overlaid on the flag.  Now all I get is a vague keyboard icon, and can't find the settings for this.  Update 2: this seems to be a , and is now back in Maverick PreparedStatement IN clause alternatives? Install MS Truetype Fonts system-wide for all users I would like to install the MS Truetype Fonts that come through the package ttf-mscorefonts-installer, so I did:  sudo apt-get install ttf-mscorefonts-installer   Accepting the license, the process completes without any errors. The fonts end up in     /usr/share/fonts/truetype/msttcorefonts   as expected. Just to be sure, I also did a  sudo fc-cache -f -s -v   which among other things says in its output:     /usr/share/fonts/truetype/msttcorefonts: caching, new cache contents: 60 fonts, 0 dirs   So far, so good (and inline with question ) However, when I then open any font dialog (e.g. in OpenOffice or the font dialog of the terminal) I don't see all of the new fonts. For Arial, the standard form is missing, but bold and italic are there. Times New Roman is missing altogether.  I can use nautilus to browse to the font directory, double click the Arial.ttf file and see the font in all its beauty. I can even click the install button then and the font is copied over to my personal ./fonts directory and from there on visible to my apps. But it is not picked up from the system directory.  How do I get these fonts available system-wide for all users? How can I disable javascript popups/alerts in Chrome? Sorry if it's been asked. I've already found several solutions that aren't working. Not sure what I'm doing wrong.   I don't want to disable all javascript, only Javascript alert boxes. The ones that pop up and force you to click OK or X to close them.  I've found user scripts that claim to do this (example:  ). I've put chrome on the dev channel, start chrome with the --enable-user-scripts switch, the script shows up as installed.  But I still get the alert boxes.  An example alert box that isn't getting disabled is at  - put in any garbage word into the word validator on the right sidebar. You get a popup telling you it's not a word. Java Generics: List, List, List How do I pre-populate a jQuery Datepicker textbox with today's date? I have a very simple jQuery Datepicker calendar:  $(document).ready(function(){     $("#date_pretty").datepicker({      }); });   and of course in the HTML...  &lt;input type="text" size="10" value="" id="date_pretty"/&gt;   Today's date is nicely highlighted for the user when they bring up the calendar, but how do I get jQuery to pre-populate the textbox itself with today's date on page load, without the user doing anything?  99% of the time, the today's date default will be what they want.