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
Empty file added app/src/models/__init__.py
Empty file.
10 changes: 8 additions & 2 deletions app/src/models/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def fibonacci(n):
def ackermann(m, n):
return


@staticmethod
def factorial(n):
return
fact=1
if n==0:
return 1
else:
for i in range(1,n+1):
fact=fact*i
return fact
8 changes: 6 additions & 2 deletions app/src/views/math_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def fib_n():
def ack_mn():
return ""


@math.route("/fact", methods=["POST"])
def fact_n():
return ""
n = request.form["fact_n"]
if not validations.validate_int(n):
# in case of invalid input, return HTTP response code for Bad Request
return "Please enter a valid input!", 400
return str(Compute.factorial(int(n)))
6 changes: 6 additions & 0 deletions app/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<input name="fib_n" placeholder="Enter Integer 'N'">
<input type="submit">
</form>
<br>
<form method="POST" action="/fact">
Factorial(n):<br>
<input name="fact_n" placeholder="Enter Integer 'N'">
<input type="submit">
</form>
</body>

</html>
Empty file added app/test/__init__.py
Empty file.
5 changes: 4 additions & 1 deletion app/test/test_compute.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from compute import Compute
from app.src.models.compute import Compute


def test_fibonacci():
Expand All @@ -7,6 +7,9 @@ def test_fibonacci():


def test_ackermann():
pass


def test_factorial():
assert Compute.factorial(0)==1
assert Compute.factorial(3)==6