knative-report-functions/isprime-python/app.py

24 lines
521 B
Python
Raw Normal View History

2019-10-08 18:16:16 +02:00
import os
from flask import Flask
app = Flask(__name__)
@app.route('/')
2019-10-08 18:42:36 +02:00
def isprime():
n = os.environ.get('TARGET', '42069')
if n == 2 or n == 3: return "Prime"
if n < 2 or n%2 == 0: return "Not Prime"
if n < 9: return "Prime"
if n%3 == 0: return "Not Prime"
r = int(n**0.5)
f = 5
while f <= r:
if n%f == 0: return "Not Prime"
if n%(f+2) == 0: return "Not Prime"
f +=6
return "Prime"
2019-10-08 18:16:16 +02:00
if __name__ == "__main__":
2019-10-08 18:42:36 +02:00
app.run(debug=True,host='0.0.0.0',port=int(os.environ.get('PORT', 8080)))