Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions calculator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,27 @@ def ADD():
sum=a+b
response = "sum of 2 numbers = " + str(sum)
return response

@app.route("/expo", methods=["POST"])
def expo():
jsonStr = request.get_json()
jsonObj = json.loads(jsonStr)

a=int(jsonObj['N1'])
b=int(jsonObj['N2'])
x=a
y=b

ans=1;
while(b):

if(b&1): ans = (ans*a)
a = (a*a)
b=b>>1

response = str(x) + "to the power " +str(y)+ " equals " +str(ans)
return response

@app.route("/xyz", methods=["POST"])
def XYZ():
jsonStr = request.get_json()
Expand All @@ -29,15 +49,6 @@ def XYZ():
# Logic for function assigned to you as in pdf

return 1
def subtract(a,b):
jsonStr = request.get_json()
jsonObj = json.loads(jsonStr)
a=int(jsonObj['N1'])
b=int(jsonObj['N2'])
return a-b




if __name__== "__main__":
app.run()
app.run()
3 changes: 2 additions & 1 deletion calculator/templates/InputOutput.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ <h2>Example</h2>
<form name="my_form" >
Please enter first number &nbsp; <input type="text" name = "N1"><br>
Please enter second number &nbsp; <input type="text" name = "N2"><br>
<input type="button" class="btn btn-sm" onclick="submitData('add')" value="add">
<input type="button" class="btn btn-sm" onclick="submitData('add')" value="add">
<input type="button" class="btn btn-sm" onclick="submitData('expo')" value="expo">
<input type="button" class="btn btn-sm" onclick="submitData('xyz')" value="xyz">
<!-- Add your input statements here -->
</form>
Expand Down