AndreiL
Welcome to AndreiL.
Enjoy your time.
Please log in.

Prime numbers in range - Python algorithm

Go down

Prime numbers in range - Python algorithm

Post by Lucaci Andrei on Thu Mar 08, 2012 10:31 pm

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'''
Created on Mar 9, 2012

@author: sin
'''
def trys(s):
try:
int (s)
except:
print "Error!\nNeeded integer, got string. "

def ver_prim(a):
for i in range(2, a / 2):
if (a % i) == 0: return False
return a

def main():
nr = []
x = raw_input("a= ")
trys(x)
y = raw_input("b= ")
trys(y)
for i in range(int(x), int(y) / 2):
if ver_prim(i):nr.append(i)
print "The prime numbers are: "
for i in range(0, len(nr)):
print nr[i],

main()

avatar
Lucaci Andrei
"Tata Lor"


Number of messages : 222
Points : 2266743
Reputation : 1007
Registration date : 2008-08-15
Age : 25
Location : Cluj-Napoca

View user profile http://www.andreil.wgz.ro

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum