Question

In: Computer Science

Create a new Python 3 Jupyter Notebook. Create one python code cell for the problem below....

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:

  1. Define a function with the following characteristics:
    • The function's purpose will be calculating a factORRial (similar to a mathematical factorial but purposefully different in important ways), so it should be named appropriately.
    • It must accept one parameter, which is the number it will be calculating the factorrial of. Name this parameter appropriately.
    • It must have an appropriate docstring.
    • If the parameter is equal to1, define a new variable as 1. This new variable will be used as the return value, so name it accordingly
    • If the parameter is equal to or less than 0, define the same variable you created in the previous bullet point as 0. Use an "else-if" block for this logic.
    • In an "else" block:
      • Print out the value of the parameter in a nicely formatted message conveying that you are calculating the factorrial of that number.
      • Define a new variable to be the parameter minus 1.
      • Define another new variable as the factorrial of variable you just created in the previous bullet point. Use a recursive call to the function you are currently building to calculate that factorrial.
      • Multiply the parameter by the variable you just defined in the previous bullet point and store it in the variable you created earlier to hold the return value.
    • The last line of the function should return the variable you defined as the return value.
  2. In your main code section, call the function defined in step 1 to calculate the factorrial of 10 and store it in a variable.
  3. Next, call the same function to calculate the factorrial of -10 and store it in a different variable.
  4. Print out both of the results using a single format string with a friendly (or funny) message

Rubric:

  • Adequate comments, readability, etc.
  • Checks for case 1
  • Checks for case equal to or less than 0
  • Checks for everything else
  • Makes appropriate recursive call
  • Calculates factorrial of 10
  • Calculates factorrial of -10
  • Uses a format string for both calculations
  • Uses docstring
  • Prints parameter for each call of function in else block

Solutions

Expert Solution

# 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)

  


Related Solutions

create a new Python 3 Jupyter Notebook.. Create one python code cell for the problem below....
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. Problem: Define a function with the following characteristics: The function's purpose will be checking that a number matches another, so it should be named appropriately. It must accept one parameter, which is the number...
Create a new Python 3 Jupyter Notebook. Create one python code cell for the problem below....
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. *Problem:* 1. Define a function with the following characteristics: * The function's purpose will be checking that a number matches another, so it should be named appropriately. * It must accept one parameter, which...
Create a new Python 3 Jupyter Notebook. At the top, be sure to name your notebook...
Create a new Python 3 Jupyter Notebook. At the top, be sure to name your notebook as "*assignment 2.08 - Your Name Here.ipynb*" (obviously, replace the "Your Name Here" part with your actual name). Create a single python cell to program the following specifications. Use what you've learned on this page to: 1. Find the index of "lmno" in the English alphabet using an appropriate instruction and store it in a variable. (hint: you'll need to define a string that...
Python HW Open a new Jupyter notebook Create a new function named fibonacci() that takes one...
Python HW Open a new Jupyter notebook Create a new function named fibonacci() that takes one required parameter: maxint, an integer that will serve as the upper bound of the loop Following the example on the Python tutorial: https://docs.python.org/3/tutorial/introduction.html#first-steps-towards-programming Our implementation will have a few changes: While you will use a while loop to make a Fibonacci sequence, the upper bound of the sequence will be your maxint parameter. Store the results into a list and append each new generated...
Problem: Perform the word counter problem through MapReduce. Tools: Anaconda/Python 3/Jupyter Notebook Example word: “One a...
Problem: Perform the word counter problem through MapReduce. Tools: Anaconda/Python 3/Jupyter Notebook Example word: “One a penny, two a penny, hot cross buns.” Submitted files: (1) Source code (adding comments); (2) Supporting document for code comments
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1,...
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1, 2, 3, 5, 8, … 2. Check if a number is an Armstrong number A positive integer is called an Armstrong number of order n if abcd... = a^n + b^n + c^n + d^n + ... In case of an Armstrong number of 3 digits, the sum of cubes of each digits is equal to the number itself. For example: 153 = 1*1*1...
What is the python code to solve this type of nonlinear equation in jupyter notebook 16cos2x+16sin2x-40.1cosx+2.3sinx+16.223=0...
What is the python code to solve this type of nonlinear equation in jupyter notebook 16cos2x+16sin2x-40.1cosx+2.3sinx+16.223=0 Please show the code clearly.
Write a python programme in a Jupyter notebook which asks the user to input the number...
Write a python programme in a Jupyter notebook which asks the user to input the number of radioactive nuclei in a sample, the number at a later time, and the elapsed time. The programme should calculate and display the decay constant and the half-life. The decay is described by the equations: ? = ? ?−?? ?0 ?1/2 = ln (2) . Test your programme a sample that contains 4.00x108 nuclei initially and 1.57x107 nuclei after 150 seconds. SO THEREFORE A...
Create individual python code cells for each of the three problems below. In each code cell,...
Create individual python code cells for each of the three problems below. In each code cell, use any additional variables and comments as needed to program a solution to the corresponding problem. When done, download the ipynb file and submit it to the appropriate dropbox in the course's canvas page . 1. a. Cell Number 1 * Recreate the same list of dictionaries you used during assignment 2.09. (Scroll down to see assignment 2.09 instructions) * Create another variable and...
Create individual python code cells for each of the three problems below. In each code cell,...
Create individual python code cells for each of the three problems below. In each code cell, use any additional variables and comments as needed to program a solution to the corresponding problem. When done, download the ipynb file and submit it to the appropriate dropbox in the course's canvas page . 1. a. Cell Number 1 * Recreate the same list of dictionaries you used during assignment 2.09. (Scroll down to see assignment 2.09 instructions) * Create another variable and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT