python script to give a list of prime no.

Peter J. Holzer hjp-python at hjp.at
Sun Apr 5 10:07:44 EDT 2020


On 2020-04-05 05:22:45 -0700, Sathvik Babu Veligatla wrote:
> I am new to python, and i am trying to output the prime numbers
> beginning from 3 and i cannot get the required output. It stops after
> giving the output "7" and that's it.

A technique I learned when I started programming (back in the days when
computers were made from bones and rocks), is to "play computer":

Grab a piece of paper and a pencil. Make a column for each variable (a,
l, and i in your case). Then walk through the code line by line, think
about what each line does, and every time a new value is assigned to a
variable, note the new value on your paper.

Do the values of the variables change the way you expect them to? If
not, why not?

        hp

PS: You can also single-step through the program in a debugger, but I
think doing this by hand on a piece of paper is very useful, especially
for a beginner, since it forces you to think what happens (The downside
is of course that you may make mistakes - but then you can learn from
them).

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20200405/db40a1b3/attachment.sig>


More information about the Python-list mailing list