In: Computer Science
Create a new Python 3 Jupyter Notebook.
Create one python code cell for the problem below. Use any additional variables and comments as needed to program a solution to the corresponding problem. All functions should be defined at the top of the code in alphabetical order.
When done, download the ipynb file and submit it to the appropriate dropbox in the course's canvas page.
Problem:
Rubric:
# Python program to find the factorial of 10 and -10
# Function factorial_using_recursion is used to calculate the factorial of any number.
def factorial_using_recursion(number) :
"""number is the variable whose factorial we have to calculate."""
# if number is 1, then define a new variable and initialize it as 1.
If number == 1:
result = 1
# if number is less than or equal to 0, then define a new variable and initialize it as 0.
elif number <= 0:
result = 0
# if number is greater than 1, then calculate the factorial of that number.
else:
print("Calculating the factorial of the number : ", number)
temp = number-1
result = number*factorial_using_recursion(temp)
return result
# Calculating the factorial of 10
factorial_10 = factorial_using_recursion (10)
# Calculating the factorial of 10
factorial_minus_10 = factorial_using_recursion (-10)
""" Printing the factorial of 10 and -10. """
print("Factorial of 10 is : ", factorial_10, " Factorial of -10 is : ", factorial_minus_10)