Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import functools
- from flask import Flask, Response
- app = Flask(__name__)
- @functools.lru_cache(maxsize=None)
- def fibonacci(i):
- a, b = 0, 1
- for j in range(i):
- a, b = b, b+a
- return b
- @app.route('/fib/<number>')
- def render_fib(number):
- try:
- num = int(number)
- except Exception:
- return Response("400 Bad Request", status=400)
- if num > 500000:
- return Response("403 Forbidden", status=403)
- resp = str(fibonacci(num)) + "\n"
- return Response(resp, mimetype='text/plain')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement