Variable labeled "undefined", despite being defined within a subroutine Here is the code:  def rand():   import random   num = (random.randint(1000,9999))   print(num)  rand() print(num)   Within the subroutine, the variable "num" is printed successfully. However, outside of it, when printing is attempted, the following error message is displayed:  Traceback (most recent call last):   File "main.py", line 8, in &lt;module&gt;     print(num) NameError: name 'num' is not defined   Why does this happen, and what are the ways I can work around it?
Short description of the scoping rules? 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.
If $A$ is a square matrix and $A^2 = 0$ then $A=0$. Is this true? If not, provide a counter-example. This is a proof question and I am not sure how to prove it. It is obviously true if you start with $A = 0$ and square it.   I was thinking:  If $ A^2 = 0 $  then $ A A = 0 $  $ A A A^{-1} = 0 A^{-1}$  $I\,A = 0 $   but the zero matrix is not invertible and that it was not among the given conditions.  Where's a good place to start? I am using XeTeX and have the following short document:  \documentclass[a4paper,12pt]{article} \usepackage{amsmath,amsthm} \usepackage[MnSymbol]{mathspec} \usepackage[no-sscript]{xltxtra} \defaultfontfeatures{Mapping=tex-text} \setallmainfonts{Minion Pro}  \begin{document}  $\phi, \varphi, \delta \ldots A \vee B$  \end{document}    Now no matter what font I am using the punctuation marks in math mode (commas, dots, \ldots etc.) come out in Computer Modern. Is there a way to change this? We have a few cases of chat accounts remaining without valid parent account:  and  for example. What should mods do when that happens:  delete the chat account notify the SE team so they can reattach or clean it up leave it as is: it's a normal situation a cold vs flu / the flu Have you got a cold? Have you got flu? Have you got the flu?  Why can't we say a flu or the cold in the previous examples? "On their back" or "on their backs"? After the therapy, eight children (43%) became able to crawl/move on their back.   Or should I use "on their backs"?   Singular because each child only has one back, or plural because we're dealing with eight backs? Can I "fill" an empty object? The bijection between homogeneous prime ideals of $S_f$ and prime ideals of $(S_f)_0$ For $f$ in dual space, there exists $x$ with norm 1 and $f(x)=\|f\|$ if space is reflexive (and nontrivial) Let $X\ne\{0\}$ be a reflexive space and let $f\in X^*$, where $X^*$ is the dual of $X$. I want to know: in general, does there exist an $x\in X$ with $\|x\|=1$, and $f(x)=\|f\|$, where $\|f\|$ is defined as $\sup\{|f(x)|:x\in X,\|x\|=1\}$?  I know this is true for $\mathbb{R}^n$ with the norm from the standard inner product, but I'm wondering if it is true in general. I have an Asus Sabertooth Z170 motherboard, with a Samsung 950 Pro m.2 NVMe drive on it. I've heard in the past that installing Windows 7 on an NVMe drive was a significant amount of work. Its now August 2016, is it still difficult? I've seen updates from Microsoft saying they've added support for NVMe in Windows 7.  Can I just download Windows 7 from Microsoft () and put it on a USB drive and install?  Is it harder than that? Help with proof that $\mathbb Z[i]/\langle 1 - i \rangle$ is a field. Which is the best visualization for contingency tables? Which is best plot, from statistical standpoint, to show a , which is typically being analyzed by chi-square test? Is it a dodged barplot, stacked barplot, heatmap, contour plot, jitterred scatterplot, multiple lines plot or something else? Should one show absolute values or percentages?  Edit: Or as @forecaster suggests in the comments, the table of numbers is itself a simple plot and should be sufficient. Regex pattern to choose data BETWEEN matching quotation marks Reading Chapter 2 of Koblitz's Introduction to Elliptic Curves and Modular Forms, I got stuck on the following question. I would like to proceed my reading, so I would appreciate any hint to this. I have no background in Algebraic Number Theory, but if someone explains in that language, I would like to see it and learn it as much as I can at this moment. References will also be appreciated!  Let $q$ be a power of prime $p$ such that $q \equiv 1 \mod 4$ and $p \nmid 2n$.  Question. Let $\chi_{4} : \mathbb{F}_{q}^{*} \rightarrow S^{1}$ be the character of order $4$, show that $\chi_{4}(-4) = 1$.  The hint in the book says we may show that $\chi_{4}(4) = \chi_{4}(-1) = 1$ for $q \equiv 1 \mod 8$ and $\chi_{4}(4) = \chi_{4}(-1) = -1$ for $q \equiv 5 \mod 8$.  If $q \equiv 1 \mod 8$, then $\chi_{4}(4) = \chi_{4}(2)^{2} = \chi_{2}(2) = \pm 1$, where $\chi_{j}$ denotes the character of order $j$. So I think $2$ must be quadratic residue in this case, but I cannot figure out why. How can I run blender from command line or a python script without opening a GUI? I'm interested in using Blender for producing images, 3d files, or calculating geometry on a server.  Can I make blender run a python script without opening a GUI?  If not, can I incorporate Blender's python API into my own python script without running a GUI? Cloning a Non-Standard Svn Repository with Git-Svn How do I show that $x^4-10x^2+1$ is irreducible over $\mathbb{Q}$? Someone says I should use the rational root test, but I don't exactly know how that applies. Thanks for any input. Why am I getting 50V at a light when the switch is off? Request Web Page in c# spoofing the Host I need to create a request for a web page delivered to our web sites, but I need to be able to set the host header information too.  I have tried this using HttpWebRequest, but the Header information is read only (Or at least the Host part of it is).  I need to do this because we want to perform the initial request for a page before the user can.  We have 10 web server which are load balanced, so we need to request the file from each of the web servers.    I have tried the following:  HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://192.168.1.5/filename.htm"); request.Headers.Set("Host", "www.mywebsite.com"); WebResponse response = request.GetResponse();   Obviously this does not work, as I can't update the header, and I don't know if this is indeed the right way to do it. Getting file names without extensions I am stuck on the following problem that says:       a) Find a weak formulation for the partial differential equation $${\partial u\over\partial t\ }+ c{\partial u \over \partial x\ }=0$$    b) Show that $u=f(x-ct)$ is a generalized solution of $${\partial u\over\partial t\ }+ c{\partial u \over \partial x\ }=0$$ for any distribution $f$    My Attempt:   I know that in order to find a weak form of a pde, we need to multiply it by a test function, then integrate it. Also, to find a generalized solution, we need to find a weak solution and just multiply it by the Heaviside function.  Let's take any test function $\phi $, then we have (integrating by parts second part of the integral) $$\int_{\Omega } ( {\partial u\over\partial t\ }+ c{\partial u \over \partial x\ })*\phi(x) dx= \int_{\Omega } {\partial u\over \partial t}\phi(x) dx - c\int_{\Omega } u(x,t)\phi'(x)dx$$ where $\phi $ vanishes at boundaries. So, is it the final form or can we proceed further? And how am I supposed to find a generalized solution?  Can someone help me out? Thanks in advance for your time.