Introduce old redir program
[lcapit-junk-code.git] / prime / prime.py
blob1ca0bbd192cdc532e79f0596780da7056857c3b9
1 #!/usr/bin/python
3 # Check if a number is prime (brute force)
5 # Luiz Fernando N. Capitulino
6 # <lcapitulino@gmail.com>
8 from sys import exit, stdout, argv
10 def is_prime(num):
11 "Check if a number is prime (brute force)"
12 if num < 2:
13 return False
15 for i in range(2, num):
16 if not (num % i):
17 return False
18 return True
20 def main():
21 if len(argv) != 2:
22 stdout.write('Usage: prime < number >\n')
23 exit(1)
25 num = int(argv[1])
26 if is_prime(num):
27 print 'is prime'
28 exit(1)
29 else:
30 print 'is not prime'
31 exit(0)
33 if __name__ == "__main__":
34 main()