From 7750143196754999dc8ffdef9654bf7c9340590e Mon Sep 17 00:00:00 2001 From: arnaugamez Date: Wed, 25 Oct 2017 20:07:25 +0200 Subject: [PATCH 1/2] Add recursive factorial function --- fact.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 fact.py diff --git a/fact.py b/fact.py new file mode 100644 index 0000000..a0a9cd9 --- /dev/null +++ b/fact.py @@ -0,0 +1,15 @@ +def fact(n): + + if n < 0: + return("Error, factorial function is not defined for negative values") + if n == 0: + return 1 + + return n*fact(n-1) + +try: + n = int(raw_input("Enter your number to factorize: ")) + print(fact(n)) + +except ValueError: + print("You must enter an integer number!") From 6ebe4fb389c27874533245c95a285b632f8e114b Mon Sep 17 00:00:00 2001 From: arnaugamez Date: Wed, 25 Oct 2017 21:00:07 +0200 Subject: [PATCH 2/2] Add sum algorithm --- SimpleAddition/alternative_sum.py | 9 +++++++++ fact.py | 15 --------------- 2 files changed, 9 insertions(+), 15 deletions(-) create mode 100644 SimpleAddition/alternative_sum.py delete mode 100644 fact.py diff --git a/SimpleAddition/alternative_sum.py b/SimpleAddition/alternative_sum.py new file mode 100644 index 0000000..af40dfd --- /dev/null +++ b/SimpleAddition/alternative_sum.py @@ -0,0 +1,9 @@ +try: + x = float(raw_input("Enter first number: ")) + y = float(raw_input("Enter second number: ")) + + result = x+y + print('Result: ' + str(result)) + +except ValueError: + print("Error. Input cannot be interpreted as a number") diff --git a/fact.py b/fact.py deleted file mode 100644 index a0a9cd9..0000000 --- a/fact.py +++ /dev/null @@ -1,15 +0,0 @@ -def fact(n): - - if n < 0: - return("Error, factorial function is not defined for negative values") - if n == 0: - return 1 - - return n*fact(n-1) - -try: - n = int(raw_input("Enter your number to factorize: ")) - print(fact(n)) - -except ValueError: - print("You must enter an integer number!")