Question
This will be done using Python. Write each of the following functions using Python. The function header MUST be written as specified. In your main
This will be done using Python. Write each of the following functions using Python. The function header MUST be written as specified. In your main code test all of the specified functions. Each function must have a comment block explaining what it does, what the parameters are and what the return value is.
Please remember the following two guidelines:
unless the purpose of the function is to generate output DO NOT write to the screen within the function (output for debugging purposes does not apply)
unless the purpose of the function is to ask the user for a value DO NOT ask the user for a value within the function
Required functions
def square (intValue): This function returns the square of intValue.
def summation (intValue): This function returns the summation of 1 to intValue. You can assume that intValue will be positive. For example, summation (5) would return 15 (1 + 2 + 3 + 4 + 5).
def sumOfSquare (intValue): This function return the sum of the squares from 1 to intValue. For example, sumOfSquares(5) would return 55 (1 + 4 + 9 + 16 + 25). You MUST use a loop and the square function to determine the returned value.
def factorial (intValue): This function returns the factorial of 1 to intValue. You can assume that intValue will be positive. For example, factorial (5) would return 120 (1 * 2 * 3 * 4 * 5).
def distance (x1, y1, x2, y2): This function returns the distance between two points. x1, y1 will be the first point, and x2, y2 will be the second point. The formula is distance = . You will want to look at the functions offered by the Math class to help with this formula.
def isOdd (int intValue): This function will return True if intValue is odd, otherwise it returns False.
def isEven (intValue): This function will return True if intValue is even, otherwise it return False. This function MUST use isOdd to determine the returned value. The point behind this function is to minimize the amount of redundant work that is done in our code, not that determining odd or even is a lot of work. Its the concept more than the reality of the code in this case.
def approximateE (iterations): You can approximate e using the following formula: e = 1 + 1 / 1! + 1 / 2! + 1 / 3! + 1 / 4! + 1 / iterations!
Write a function that accepts the number of iterations used to approximate e. You can assume that iterations will be positive. Return the approximated value of e. Use the factorial function required by the assignment in this function.
def approximatePi (iterations): The German mathematician Gottfried Leibniz developed the formula to approximate PI: = 4 * (1 -1/3 + 1/5 1/7 + ) Note the alternative subtraction and addition of the fractions in the formula.
Write a function that accepts the number of iterations used to approximate PI. The number of iterations will be used to determine the number of fractions used in the formula. For example, one iteration would implement the formula of = 4 * (1 - 1/3) You can assume that iterations will be positive. Return the approximated value of PI.
Requirements
Complete comment section that includes your name, id number, program number and a brief description of the prog
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started