Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your function doesn't return anything, so that's why when you use it with the <code>print</code> statement you get <code>None</code>. So either just call your function like this:</p> <pre><code>leapyr(1900) </code></pre> <p>or modify your function to return a value (by using the <code>return</code> statement), which then would be printed by your <code>print</code> statement.</p> <p><strong><em>Note</em>: This does not address any possible problems you have with your leap year computation, but ANSWERS YOUR SPECIFIC QUESTION</strong> as to <em>why</em> you are getting <code>None</code> as a result of your function call in conjunction with your <code>print</code>.</p> <p><em>Explanation</em>:</p> <p>Some short examples regarding the above:</p> <pre><code>def add2(n1, n2): print 'the result is:', n1 + n2 # prints but uses no *return* statement def add2_New(n1, n2): return n1 + n2 # returns the result to caller </code></pre> <p>Now when I call them:</p> <pre><code>print add2(10, 5) </code></pre> <p>this gives:</p> <pre><code>the result is: 15 None </code></pre> <p>The first line comes form the <code>print</code> statement <em>inside</em> of <code>add2()</code>. The <code>None</code> from the print statement when I call the function <code>add2()</code> which does <strong>not</strong> have a return statement, causing the <code>None</code> to be printed. Incidentally, if I had just called the <code>add2()</code> function simply with (note, <strong><em>no</em></strong> <code>print</code> statement):</p> <pre><code>add2() </code></pre> <p>I would have just gotten the output of the print statement <code>the result is: 15</code> without the <code>None</code> (which looks like what you are trying to do).</p> <p>Compare this with:</p> <pre><code>print add2_New(10, 5) </code></pre> <p>which gives:</p> <pre><code>15 </code></pre> <p>In this case the result is computed in the function <code>add2_New()</code> and no print statement, and returned to the caller who then prints it in turn.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload