【Python】標準ライブラリで算術演算 Part1【AWS】
この記事はPython 3.9のAWS Lambdaで算術計算する方法を解説したものです。
こんにちは!らびです。今回はPython 3.9のAWS Lambdaで計算を試していきます。
標準ライブラリでどこまでできるか楽しみですね。
Python Lambdaのコード
早速ですがPythonのコードです。今回は三角関数を計算していきます。
1/4π(45°)のsin、cos、tan値
import json import math def lambda_handler(event, context): answer_sin = math.sin(math.pi / 4) answer_cos = math.cos(math.pi / 4) answer_tan = math.tan(math.pi / 4) return { "statusCode": 200, "body": json.dumps({ "message": "sin:" + str(answer_sin ) + " cos:" + str(answer_cos ) + " tan:" + str(answer_tan ), }), }
実行結果はこんな感じだジョ。
piが有限として計算されているので、tanの結果が0.999…になっていますね。