Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Either reference the functions on the module object:</p> <pre><code>import gm def stats(list): stats = {} # empty dict named stats stats['average'] = gm.avg_list(list) # Stats(key)[average] = mean of the list of numbers [values] stats['median'] = gm.median(list) # same for median return stats </code></pre> <p>or import the functions directly into the global namespace:</p> <pre><code>from gm import avg_list, median def stats(list): stats = {} # empty dict named stats stats['average'] = avg_list(list) # Stats(key)[average] = mean of the list of numbers [values] stats['median'] = median(list) # same for median return stats </code></pre> <p>Note that <strong>you should not name a variable <code>list</code></strong>. This masks the built-in <code>list()</code> function / type and can cause confusing errors later if you need to use it.</p> <p>You can write</p> <pre><code>stats = {} # empty dict named stats stats['average'] = avg_list(list) # Stats(key)[average] = mean of the list of numbers [values] stats['median'] = median(list) # same for median return stats </code></pre> <p>as</p> <pre><code>stats = {'average': avg_list(list), 'median': median(list)} return stats # or just return the dict literal, no real need to give it a name. </code></pre> <p>I think you should look at the first branch of your <code>median</code> function. Does the list need to be sorted there too, like in the second branch?</p> <p>Your <code>avg_list</code> function is also masking a built-in function, <code>sum()</code>, which you could use here instead of manually adding:</p> <pre><code>def avg_list(list): avg = float(sum(list))/len(list) print avg </code></pre> <p>Finally, look at the last line of that function -- it's <code>print</code>ing the <code>avg</code>, but <code>stats</code> is expecting it to <code>return</code> the <code>avg</code>. The two aren't the same.</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. 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