Python program to find prime numbers within a range.

Below is the python program to list all the prime numbers in 1 to 100.
——————————————————————
prime_list = []
for i in range(1,101,2):
prime = True
#if i%2 != 0:
for j in range(2,int(i/2)):
if i%j == 0:
prime = False
if prime :
prime_list.append(i)
print (“%s”%prime_list)
——————————————————————

Advertisements

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: