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
22 changes: 21 additions & 1 deletion app/src/models/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,25 @@ def ackermann(m, n):
return


@staticmethod
def factorial(n):
return
if n==1:
return n
else:
res=1
for i in range(1,n+1):
res=res*i
return res
if n< 0:

print("Sorry, factorial does not exist for negative numbers")
if n == 0:

print("The factorial of 0 is 1")







10 changes: 7 additions & 3 deletions app/src/views/math_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Set the route and accepted methods
@math.route('/')
def index():
return "This is an example app"
return "This is an my first web app"


@math.route('/home')
Expand All @@ -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):
return "enter valid number"
return str(Compute.factorial(int(n)))

5 changes: 5 additions & 0 deletions app/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<input name="fib_n" placeholder="Enter Integer 'N'">
<input type="submit">
</form>
<form method="POST" action="/fact">
factorial(n):<br>
<input name="fact_n" placeholder="ente the number">
<input type="submit">
</form>
</body>

</html>
2 changes: 2 additions & 0 deletions app/test/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ def test_ackermann():


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