Question: Write each of the following functions using Python: 1. def inputWithinRange (lowValue, highValue): This function will ask for a number from the keyboard. The function
Write each of the following functions using Python:
1. def inputWithinRange (lowValue, highValue): This function will ask for a number from the keyboard. The function will only return a value that is within the inclusive range of lowValue to highValue. If the entered value is not within the provided range, the function will ask again until the user has entered an acceptable value. The function will return the accepted value.
2. def doContinue (prompt): This function will ask for a string using the prompt parameter. The function will return True if the user enters an upper or lower case yes or False if the user enters an upper or lower case no. Any other entered value will cause the function to ask again until an acceptable value has been entered.
3. def square (intValue): This function returns the square of intValue.
4. 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).
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 the square function to determine the returned value.
6. 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).
7. 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.
8. def isOdd (int intValue): This function will return True if intValue is odd, otherwise it returns False.
9. 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.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
