Sun K.

asked • 06/28/14

How do I write this program?

Write a python program that finds all of the prime numbers between 1 and 100.
 
This is what I wrote:
print [n for n in xrange(1, 100) if n%n==0]
 
and it gave me a bunch of numbers from 1 to 100 but there are many numbers that aren't prime numbers. So how do I write this program? And please tell me the right answer. Thanks.
 
But do you have a shorter code than that? 

2 Answers By Expert Tutors

By:

Kirt U. answered • 08/25/14

Tutor
4.7 (187)

Expert computer programming and math tutor

Peter H. answered • 06/28/14

Tutor
New to Wyzant

Tutoring in Math, Science, and Computer Engineering

Peter H.

Why do you need a shorter code ?
How short does it need to be ?
Report

06/29/14

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.