月度归档:2011年06月

platform

Platform is a product engine, its owner would effect product trends. Microsoft’s windows and Linux/Unix are platforms based on personal computer, Google, Facebook and Live.com have been developing their own platform based on internet. If you have been used google search engine, google earth, google doc, gmail, reader, map etc, you may find there have many API supplied with these products, which can be used to develop your own products,for example, you can develop a guide system based on google earth. These products and API can be viewed as platforms. Platform is a great thing, which can be used to improve the power and efficiency of developer, also the manufacturer’s power in market.

作者:豆博草堂

用python写的一个判断是否为质数的函数

 

#!/usr/bin/python
# Judge whether a interger is a prime.
#isprime.py

import sys
import math

def isPrime(num):
    if not isinstance(num, int):
       return False
    anum = num
    if anum < 0:
       anum = math.fabs(anum)
    if anum == 1:
       return False
    if anum == 2 or anum == 3:
       return True
    if math.fmod(anum, 2) == 0:
       return False
    endN = math.sqrt(anum) + 1
    i = 3
    ret = True
    while i < endN:
       if math.fmod(anum, i) == 0:
          ret = False
          break;
       i += 2
    return ret

if __name__ == "__main__":
      if len(sys.argv) < 2:
         print "usage is:"
         print "python isprime.py <value1> [< <space>value2>< <space>value3>...]"
      numlist = sys.argv[1:]
      n = 0
      for num in numlist:
          try:
             n = int(num)
             if isPrime(n) :
                print num + " is a prime."
             else :
                print num + " is not a prime."
          except ValueError:
                print num + " is not a prime."

作者:豆博草堂