Simple Python API

from flask import Flask, jsonify, request
from statistics import mean, median, mode
app = Flask(__name__)@app.route("/calculate", methods=['POST'])def calculate():
data = request.get_json()
function = data['operation'].lower()
list_vals = data['operands']
if function == 'sum':
return jsonify({"answer":sum(list_vals)})
elif ((function == 'average') | (function == 'avg') | (function == 'mean')):
return jsonify({"answer":mean(list_vals)})
elif (function == 'median'):
return jsonify({"answer":median(list_vals)})
elif (function == 'mode'):
return jsonify({"answer":mode(list_vals)})

return "Operation not available"
if __name__ == "__main__":



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store