title: How do I find all primes in a user-defined range?
body: <p>I want to get a script to:
  a) check if a number within the user defined range is prime or not
  b) print the result of a check
  c) print amount of numbers checked and how many of these numbers were primes
  d) print the last prime number</p>
  <p>Here is what I have so far:</p>
  <pre><code>lower = int(input(&quot;Lower boundry: &quot;))
  upper = int(input(&quot;Upper boundry: &quot;))
  for n in range(lower, upper + 1):
      if (n &lt;= 1):
          print(n, &quot;error&quot;)
      elif (n &gt; 1):
          for x in range(2, n):
              if ((n % x) == 0):
                  print(n, &quot;not prime, because&quot;, x, &quot;*&quot;, int(n/x),&quot;=&quot;, n)
                  break
          else:
              print(n, &quot;prime&quot;)
              last = [n]  
  print(&quot;Checked&quot;, n, &quot;numbers, of which&quot;,&quot;XXX&quot;,&quot;were prime.&quot;)
  print(&quot;Last prime number found was&quot;, *last)
  </code></pre>
  <p>Question:</p>
  <ol>
  <li><p>The tool im using gives me an error. Lets say, I check the numbers 1-10. On 1 I get a notification that 1 is not prime (as intended, as n &lt;= 1). Number 2 is a prime and the programme notifies me of this. However, on 3 i get an error - &quot;incorrect output: your program printed &quot;prime3&quot;, but should have printed &quot;prime.&quot;. I don't get it. Is it the white space python seems to like so much? Or did I fail with else if use?</p>
  </li>
  <li><p>For checking the number of primes within the specified range - am I supposed to use a list to store the values generated in the for loop? The material will cover lists during later sessions, so I am guessing I am meant to use some other method. But lets say I want to use the list. Is it something like:</p>
  <pre><code> list=[]
   for y in [1,10] : 
       for z in [0,1,2,3] :
       x=y+z
       list.append(x)
  </code></pre>
  </li>
  </ol>
  <p>and the use len(list) where the XXX placeholder is ATM?</p>
  <p>Edit: Got the c) and d) to work - used list as a storage for values. Printed last value in the list for d) and used the length of the list for c). Fixed the indentation issue pointed out to me in the comments below. Still cannot get the code to run properly. In I in put 1 and 10 as bounds, the programme identifies 1 as not prime, 2 as prime and then gives error. Error text is: &quot;Incorrect output: your program printed &quot;prime3&quot;, but should have printed &quot;prime.&quot; &quot; Not really sure what is up with that.</p>