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 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 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 returnTrue 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 thatintValue 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 intValuewill be positive. For example, factorial (5)
would return 120 (1 * 2 * 3 * 4 * 5).
Code with indentation:
1 Function
2 Function
3,4&5 functions
6th function
_____________________________________________________________________________________
Outputs:
1st function output
2nd function output
3rd function output
4th function output:
5th function output
6th function output:
___________________________________________________________________________________________
Objectives Work with functions Assignment Write each of the following functions using Python. The function header MUST b...
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...
PYTHON. Write the following functions without using any predefined functions unless specified. def min (dataList) : #returns the smallest value of the data values in dataList def max (dataList): #returns the largest value def getRange (dataList) def mean (dataList) : #returns the average of data values def median (dataList): #returns the middle value of an ordered list #note: to sort the list first, may use the predefined sort function Then write a test1 function to test the above functions using...
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...
USING PYTHON PLEASE Write a program that calculates the factorial value of a number entered by the user. Remember that x! =x* (x-1)* (x-2)*... *3+ 2* 1. Your program should check the value input by the user to ensure it is valid (i.e., that it is a number > =1). To do this, consider looking at the is digit() function available in Python. If the user enters an incorrect input, your program should continue to ask them to enter a...
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:...
in Python: Write a program that allows the user to enter a number between 1-5 and returns an animal fact based on what the user entered. The program should 1. Continue to run until the user enters “quit” to terminate the program, and 2. Validate the user’s input (the only acceptable input is 1, 2, 3, 4, 5 or “quit”). You can use the following animal facts: An octopus is a highly intelligent invertebrate and a master of disguise. Elephants...
Python Programming language Write the following functions: getNumInRange(prompt, min, max) - gets a number from the user within the specified range, prompting with 'prompt' calcAvg(values) - calculates and returns the average from a supplied list of numeric values menu(somelist) - creates a numbered menu from a list of strings. Then, have the user select a valid choice (number), and return it. Use the getNumInRange() funtion to do this. getAlbum() - prompts the user for information to populate a dictionary representing...
Factorial.java This is an exercise in using repetition structures to calculate the mathematical values of the factorial function. Since methods have not yet been covered in detail, you may do the calculations in a class that contains just a main method. The looping structures require the use of count-controlled loops. This program computes the factorial function of a non-negative integer, which is written mathematically as n! (the parameter n followed by an exclamation mark). For values of n equal to...
using python Do it now 2. Write a code with two functions of squared and square_root. At the beginning your code should ask the user to enter one number. Then it should ask the user what they want to do (enter s to calculate the squared value of the entered number and enter r to perform a square root). Then based on the choice of user (using if) the program should call the proper function. Each function, when executing, should...
Hi. Could you help me write the below program? Please don't use any header other than iostream, no Chegg class, no argc/argv. Nothing too advanced. Thank you! For this assignment you are implement a program that can be used to compute the variance and standard deviation of a set of values. In addition your solution should use the functions specified below that you must also implement. These functions should be used wherever appropriate in your solution. With the exception of...