forked from suj2/AWS-Lambda_Serverless_Calculator_Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.py
More file actions
110 lines (95 loc) · 2.51 KB
/
calculator.py
File metadata and controls
110 lines (95 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import json
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
def add(event, context):
logger.info("Event logged the following ", event)
final={}
final=event['queryStringParameters']
a =float(final['a'])
b=float(final['b'])
c=a+b
res = "the result is " +str(c)
response_success={
"statusCode": 200,
"body": json.dumps(res)
}
return response_success
def subtract(event, context):
logger.info("Event logged the following ", event)
final={}
final=event['queryStringParameters']
a =float(final['a'])
b=float(final['b'])
c=a-b
res = "the result is " +str(c)
response_success={
"statusCode": 200,
"body": json.dumps(res)
}
return response_success
def multiply(event, context):
logger.info("Event logged the following ", event)
final={}
final=event['queryStringParameters']
a =float(final['a'])
b=float(final['b'])
c=a*b
res = "the result is " +str(c)
response_success={
"statusCode": 200,
"body": json.dumps(res)
}
return response_success
def divide(event, context):
logger.info("Event logged the following ", event)
final={}
final=event['queryStringParameters']
a =float(final['a'])
b=float(final['b'])
c=a/b
res = "the result is " +str(c)
response_success={
"statusCode": 200,
"body": json.dumps(res)
}
return response_success
'''
def calci(event,context):
logger.info("Event logged the following:",event)
if bool(event) ==True:
logger.info("the events dict is not empty")
res_error ={
"statusCode": 404,
"body": json.dumps("resource not found in input")
}
dict1={}
dict1=event['queryStringParameters']
a = (dict1['a'])
logger.info('the value of a is %s ', a)
b = (dict1['b'])
op = (dict1['op'])
logger.info('the value of b is %s', b)
logger.info('the op is %s', op)
a = float(a)
b=float(b)
c=0
if op=='+':
c=a+b
if op=='-':
c=a-b
if op=='/':
if b==0:
c="Division by 0"
return {"statusCode":200,"body": "Division by 0"}
c=(a/b)
if op=='*':
c=a*b
res = "the result is " +str(c)
response_success={
"statusCode": 200,
"body": json.dumps(res)
}
logger.debug( "response from calci is %s ", res)
return response_success
'''