Question

In: Computer Science

Define a function average_entries_for(integer) that takes in an integer than represents the number of times the...

Define a function average_entries_for(integer) that takes in an integer than represents the number of times the function will ask the user to input a number. The function will return the average of all the numbers entered. You must use a for loop to implement this function. (Hint: use range)

Solutions

Expert Solution

#function for calculating average of given input number of range integer
def average_entries_for(integer):
   sum=0
   for i in range(integer):
       num=int(input("Enter number : "))   #reading number of integer times
       sum=sum+num       #calculating sum of entered numbers
   average=sum/integer   #calculating average of entered numbers
   return average   #function returning result
#main program
integer=int(input("Enter integer : "))
average_Of_Numbers = average_entries_for(integer)
print("average : ",average_Of_Numbers)


Related Solutions

in Python3 The ord function in Python takes a character and return an integer that represents...
in Python3 The ord function in Python takes a character and return an integer that represents that character. It does not matter what the integer representing the character actually is, but what matters is this: ord('a') is 1 less than ord('b'), so that: x=ord('a') thisLetter = x+1 # thisLetter is the ord('b') This is a powerful fact that is used in encryption techniques, so data transferred over the web is 'ciphered so it is unreadable to others. To decipher data,...
Write a function that counts the number of times a given integer occurs in a Linked...
Write a function that counts the number of times a given integer occurs in a Linked List. What is the time complexity of your algorithm? Justify your answer in python
2. Define a function max_n(arr, n) that takes in an array and an integer as arguments....
2. Define a function max_n(arr, n) that takes in an array and an integer as arguments. Your function will then return the n largest values from that array as an array containing n elements. It is safe to assume that arr will have at least n elements. The resulting array should have the largest number on the end and the smallest number at the beginning. For Example: max_n(np.array([1,2,3,4,5]), 3) returns np.array([3,4,5]) max_n(np.array([10,9,8,7,6,5]), 4) returns np.array([7,8,9,10]) max_n(np.array([1,1,1]), 2) returns np.array([1,1])
In MATLAB define a function named primes that takes a non-negative integer, ?, as its only...
In MATLAB define a function named primes that takes a non-negative integer, ?, as its only argument and returns a row vector containing the first ? prime numbers in order. Assume that the first prime number is 2.  Other than the zeros function, the ones function, and the colon (:) operator, you may not use any Matlab built-in array functions.
Write a function lbs2lboz(p) that takes a non-negative number, p , that represents a weight in...
Write a function lbs2lboz(p) that takes a non-negative number, p , that represents a weight in pounds and outputs a pair (l,o) such that l is an integer and p=l+o/16. Write a function oz2lboz(oz) that takes a non-negative number, oz , that represents a weight in ounces and outputs a pair (l,o) such that l is an integer and oz=l*16+o. on python
Define a function digits_stars(...) which receives as input one digit (that is, an integer number greater...
Define a function digits_stars(...) which receives as input one digit (that is, an integer number greater or equal than 0 and less or equal than 9). The function should return a string. The string will have , alternating, a digit and a "*" symbol, starting with the digit 0, then a star, then the digit 1, then a star, and so on, alternating until reaching the input digit and one star symbol to end the string. As an example, the...
Write a function convert_date that takes an integer as a parameter and returns three integer values...
Write a function convert_date that takes an integer as a parameter and returns three integer values representing the input converted into days, month and year (see the function docstring). Write a program named t03.py that tests the function by asking the user to enter a number and displaying the output day, month and year. Save the function in a PyDev library module named functions.py A sample run for t03.py: Enter a date in the format MMDDYYYY: 05272017 The output will...
a program that takes an integer and outputs the resulting factorial number.
assembly x86 language program a program that takes an integer and outputs the resulting factorial number. 
File has a format Name and number, the number represents power. The name and the (integer)...
File has a format Name and number, the number represents power. The name and the (integer) power are separated by some amount of space. Importantly, any line that begins with a hash '#' are comments and they need to be ingored. Write a program that reads from that file, and prints out only the name of the hero with the strongest power. That name should be capitalized (not uppercase, but capitalized, as in 'Galadriel') Here is the heroes.txt # DC...
write a function named as cubeCalculator that takes an integer pointer as function and return its...
write a function named as cubeCalculator that takes an integer pointer as function and return its cube value , you are required to compute the cube of a number using pointer notation , return the result as an integer value , use c++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT