123456789101112131415161718192021222324252627 |
- # app.py
- from flask import Flask, request
- from werkzeug.urls import url_quote_plus
-
- app = Flask(__name__)
-
- def fizzbuzz(num):
- if num % 3 == 0 and num % 5 == 0:
- return "fizzbuzz"
- elif num % 3 == 0:
- return "fizz"
- elif num % 5 == 0:
- return "buzz"
- else:
- return str(num)
-
- @app.route('/fizzbuzz', methods=['POST'])
- def compute_fizzbuzz():
- data = request.json
- try:
- number = int(data['number'])
- return fizzbuzz(number)
- except (KeyError, ValueError):
- return "Invalid input: Please provide a valid number", 400
-
- if __name__ == '__main__':
- app.run(host='0.0.0.0', port=8080)
|