Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- prime1=[]
- #prime1 is a list in which I will store prime numbers, X.
- prime2=[]
- #prime2 is a temporary list that stores numbers that cleanly divide the number in question, X.
- x=100
- #using 100 to find all prime numbers under 100.
- y=99
- #starting with 99 because 100/100 will cleanly divide, so -1 is 99.
- while x > 0:
- #when x = 0 is where I want to stop trying to find primes.
- while y >0:
- #in this loop, after each attempt to divide into x, y will reduce itself by 1 and attempt to divide again.
- if x%y == 0:
- #in the event of a successful divide.....
- prime2.append(y)
- #the value of y is stored into the prime2 temp list.
- y=y-1
- #y is incremented, eventually down to 0 where the while loop will stop.
- if sum(prime2[:]) == 1:
- #a prime number will only successfully divide by 1. y naturally starts at x-1, so it will never include x.
- #if the sum of prime2 is 1, that means that x is a prime number because it is only divisible by 1, other than itself.
- prime1.append(x)
- #the prime number x is appended into the list prime1.
- prime2.clear()
- #prime2 is cleared for another loop.
- x=x-1
- #x increments down
- y=x-1
- #y follows and increments to -1 of x. While Loop then continues again.
- print prime1
- #after the while loop determines if numbers 100 through
- #100 are primes, it stops. At this point, all primes
- #should have been appended to the list prime1.
- #This list is then printed.
- raw_input('Press <enter> to close.')
- #this closes the program.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement