[chang@sstest python]$ cat primeno.py
#!/usr/bin/python
def if_prime_no(number_n):
yes_p = 1
if number_n > 2:
for i in range(2, number_n):
if number_n%i==0:
#print (str(i) + " is not a prime number ")
yes_p=0
if yes_p == 1:
#print (str(number_n) + " is a prime number")
return 1
else:
#print (str(number_n) + " is not a prime number")
return 0
def all_prime(number_n):
p = [2]
for i in range(2, number_n+1):
if if_prime_no(int(i))==1:
p.append(i)
return p
while True:
your_number = raw_input ("Please enter the number or 'exit' to exit:")
if your_number == 'exit':
break
else:
if if_prime_no(int(your_number))==1:
print (your_number + " is a prime number")
else:
print (your_number + " is not a prime number")
print all_prime(int(your_number))
======================================
[cng@sstest python]$ ./primeno.py
Please enter the number or 'exit' to exit:20
20 is not a prime number
[2, 3, 5, 7, 11, 13, 17, 19]
Please enter the number or 'exit' to exit:13
13 is a prime number
[2, 3, 5, 7, 11, 13]
Please enter the number or 'exit' to exit:exit
Subscribe to:
Post Comments (Atom)
-
Step 1, New a project rails new demo Step 2, Update Gemfile add paperclip, mysql2 gem, enable JavaScript runtime gem 'mysql2' ...
-
I used 7z to zip this file under Windows, try to unzip it under linux [ang@walker temp]$ gunzip 2011.sdf.zip gunzip: 2011.sdf.zip: unkno...
-
When trying to access transmission from web-browswer i got the message : 403: Forbidden Unauthorized IP Address. Either disable the IP ad...
No comments:
Post a Comment