diff --git a/app/src/models/compute.py b/app/src/models/compute.py index 4d1c761..828c7e1 100644 --- a/app/src/models/compute.py +++ b/app/src/models/compute.py @@ -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") + + + + + + + diff --git a/app/src/views/math_functions.py b/app/src/views/math_functions.py index d02273c..11881fb 100644 --- a/app/src/views/math_functions.py +++ b/app/src/views/math_functions.py @@ -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') @@ -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))) + \ No newline at end of file diff --git a/app/templates/home.html b/app/templates/home.html index b659a56..c443d9a 100644 --- a/app/templates/home.html +++ b/app/templates/home.html @@ -7,6 +7,11 @@ +