Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's quite straight-forward to print result of a function:</p> <pre><code>print buildPrimeList() </code></pre> <p>Also I've noticed that you do not convert raw_input's result (which is string) to int:</p> <pre><code>x = int(raw_input("Enter a number higher then 3 ")) </code></pre> <hr> <p>Another way to do the same thing in python might look like:</p> <pre><code>from itertools import count def is_prime(n): """Checks if given number n is prime or not.""" for i in xrange(2, n/2): if n % i == 0: return False else: return True def prime_numbers(): """Generator function which lazily yields prime numbers one by one.""" for i in count(1): if is_prime(i): yield i if __name__ == '__main__': maxprime = int(raw_input("Enter a number:")) for prime in prime_numbers(): if prime &lt; maxprime: print prime else: break </code></pre> <p>A number of python idioms and language features were used:</p> <ul> <li>generator functions and iterators [1];</li> <li>snake_case_method_naming [2];</li> <li>docstrings [3];</li> <li><code>if __name__ == '__main__': ...</code> [4].</li> </ul> <p>[1] <a href="http://www.ibm.com/developerworks/library/l-pycon/index.html" rel="nofollow noreferrer">http://www.ibm.com/developerworks/library/l-pycon/index.html</a></p> <p>[2] <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow noreferrer">PEP 8: Style Guide for Python Code</a></p> <p>[3] <a href="http://www.learningpython.com/2010/01/08/introducing-docstrings/" rel="nofollow noreferrer">http://www.learningpython.com/2010/01/08/introducing-docstrings/</a></p> <p>[4] <a href="https://stackoverflow.com/questions/419163/what-does-if-name-main-do">What does if __name__ == &quot;__main__&quot;: do?</a></p> <hr> <p><b>p.s.</b> As jellybean and rpInt noted in their answers and comments there are a number of ways to speed things up. But most likely you shouldn't do that (unless you absolutely have to) as "Simple is better than complex" [5].</p> <p>[5] <a href="http://www.python.org/dev/peps/pep-0020/" rel="nofollow noreferrer">PEP 20: The Zen of Python</a></p>
 

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