diff --git a/Factor of a given number in python b/Factor of a given number in python new file mode 100644 index 0000000..c12ae65 --- /dev/null +++ b/Factor of a given number in python @@ -0,0 +1,9 @@ +def print_factors(x): + print("The factors of",x,"are:") + for i in range(1, x + 1): + if x % i == 0: + print(i) + +num = 320 + +print_factors(num) diff --git a/Factorial of a given number in python b/Factorial of a given number in python new file mode 100644 index 0000000..3800516 --- /dev/null +++ b/Factorial of a given number in python @@ -0,0 +1,15 @@ +def recur_factorial(n): + if n == 1: + return n + else: + return n*recur_factorial(n-1) + +num = 7 + +# check if the number is negative +if num < 0: + print("Sorry, factorial does not exist for negative numbers") +elif num == 0: + print("The factorial of 0 is 1") +else: + print("The factorial of", num, "is",recur_factorial(num)) )