Question

Required functions def inputWithinRange (lowValue, highValue): This function will ask for a number from the keyboard....

Required functions 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. 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. 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. It’s the concept more than the reality of the code in this case.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code:

# importing the maths library
import math


# functions check if the input is in the provided range or not
# and returns the number if in range
def inputWithinRange (lowValue, highValue):

    while True: # using while loop for asking continously until funtion returns
        num = int(input('Enter an integer value within the range given: '))

        if num >= lowValue and num <= highValue:
            return num


# function check if user enters 'yes' or 'no'
def doContinue ():

    while True: # while loop will run till the conditions are satisfied
        string = input('Do you want to continue: ')

        if string.lower() == 'yes' :
            return True

        elif string.lower() == 'no' :
            return False


# function returns the square of given number
def square (intValue):

    return intValue ** 2


# function returns the sum of the first n numbers, where n is provided by user
def summation (intValue):

    summation = 0   # variable to store sum

    for i in range(1, intValue + 1):    # for loop will iterate from 1 to intValue incluesive
        summation += i

    return summation


# functoin returns the sum of squares of first n numbers, where n is provided by user
def sumOfSquare (intValue):

    sumOfSquare = 0 # variable to store sum of squares

    for i in range(1, intValue + 1):    # for loop will iterate from 1 to intValue incluesive
        sumOfSquare += square(i)    # here we have used previously defined function to find square of each number

    return sumOfSquare


# function to return the factorial of a given number
def factorial (intValue):

    factorial = 1   # intializing the factorial to 1

    if intValue <= 1 :  # if number is less or equal to 1 we return factorial
        return factorial

    else:
        for i in range(2, intValue):
            factorial *= i

        return factorial


# function for calculating and returning the distance between two points provided
def distance (x1, y1, x2, y2):

    distance = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)   # using the formua for calculating distance

    return distance


# functoin checks if the provided number is odd or not
def isOdd (intValue):

    if intValue % 2 == 0:   # if odd return true
        return True

    else:   # else return false
        return False


# function checks if the provided number is even or not
def isEven (intValue):

    if isOdd(intValue): # if number is odd return false
        return False

    else:   # else number is even return true
        return True

For help please comment.
For modification please comment.

Thank you.

Add a comment
Know the answer?
Add Answer to:
Required functions def inputWithinRange (lowValue, highValue): This function will ask for a number from the keyboard....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Objectives Work with functions Assignment Write each of the following functions using Python. The function header MUST b...

    Objectives Work with functions Assignment 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 unless the purpose...

  • C++ PROGRAMMING Implement a bool function whose header is given below. Inside the function, declare, ask,...

    C++ PROGRAMMING Implement a bool function whose header is given below. Inside the function, declare, ask, and get a character from the user. The function will return true if the character the user enters is NOT in either of the words, otherwise it will return false. Keep in mind that uppercase and lowercase letters are not the same. You will need to change both words and the character input by the user to the same case (upper or lower) -...

  • Functions can return a string, not just an int or a float. Write a function called...

    Functions can return a string, not just an int or a float. Write a function called everOrOdd which takes an integer parameter and returns either "Even" or "Odd" based on the value passed. In main, prompt the user for a number, called num, then pass num to evenOrOdd and display the returned value on the screen. Keep doing this until the user enters a zero. Use the following run as an example: Enter a number: 11 Odd Enter a number:...

  • Python Programming assignment : Function of Q3: def isPositive(n): if(n>=0): return True else: return False Write...

    Python Programming assignment : Function of Q3: def isPositive(n): if(n>=0): return True else: return False Write a code for function main, that does the following: -creates a variable and assigns it the value True. - uses a while loop which runs as long as the variable of the previous step is True, to get a number from the user and if passing that number to the function of Q3 results in a True value returned, then add that number to...

  • Python Programming assignment : Function of Q3: def isPositive(n): if(n>=0): return True else: return False Write...

    Python Programming assignment : Function of Q3: def isPositive(n): if(n>=0): return True else: return False Write a code for function main, that does the following: -creates a variable and assigns it the value True. - uses a while loop which runs as long as the variable of the previous step is True, to get a number from the user and if passing that number to the function of Q3 results in a True value returned, then add that number to...

  • In python, Write a function that will ask user to enter a number and find if...

    In python, Write a function that will ask user to enter a number and find if it is odd or even. Example run: Please enter a number: 5 5 is an odd number Please enter a number: 10 10 is an even number

  • def second_index(a_list, number): Accepts a list of integers and an integer, and returns the index of...

    def second_index(a_list, number): Accepts a list of integers and an integer, and returns the index of the SECOND occurrence of the integer in the list. It returns None if the number does not occur two or more times in the list. Example 1: second_index ([2,34,3,45,34,45,3,3), 3) returns 6 Example 2: second_index( [2,34,3,45,34,45,3,3), 45) returns 5 Example 3: second_index ( [2,34,3,45,134,45,3,3), 134) returns None Example 4: second_index( [2,34,3,45, 134,45,3,3), 100) returns None return None def hasEveryLetter(s): #s is a string Returns...

  • Using Python 3+ for Question P5.9 Instructions: Use one main() to call each of the functions...

    Using Python 3+ for Question P5.9 Instructions: Use one main() to call each of the functions you created. Only use one value of r and h for all the function. Ask the user for the r and h in the main() as an input, and h for all the functions. You should put the functions for areas in a separate file. ​ For example, firstDigtec7ze Write a function e digits n) (returning the number of digits in the argument returning...

  • In C++ 1.Define a function named "sumCodes" that accepts two input parameters: "s "and "pos". "s"...

    In C++ 1.Define a function named "sumCodes" that accepts two input parameters: "s "and "pos". "s" is an object of the type "string" and "pos" is a boolean value with the default argument of "true". If "pos" is "true", the function returns the summation of the ASCII codes of all the characters located at the even indices of "s" and if "pos" is "false", the function returns the summation of the ASCII codes of all the characters located at the...

  • Question 4-6 Please. Python 3.6. def main(). entered by a user. Write a program that finds...

    Question 4-6 Please. Python 3.6. def main(). entered by a user. Write a program that finds the sum and average of a series of numbers he program should first prompt the user to enter total numbers of numbers are to be summed and averaged. It should then as for input for each of the numbers, add them, and print the total of the numbers and their average 2. Write a progra m that finds the area of a circle. The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT