Python: Check the average value of the elements of a given array of numbers is a whole number or not
Average Whole Number Check
Write a Python program to check whether the average value of the elements of a given array of numbers is a whole number or not.
Sample Solution-1:
Python Code:
Sample Output:
Original array: 1 3 5 7 9 Check the average value of the elements of the said array is a whole number or not: True Original array: 2 4 2 6 4 8 Check the average value of the elements of the said array is a whole number or not: False
Explanation:
Here is a breakdown of the above Python code:
- Import Statement:
- The 'array' module is imported with the alias 'arr'.
- Test Function (test function):
- The "test()" function is defined to check if the average value of the elements in an array is a whole number.
- It calculates the sum of array elements and checks if the remainder of the sum divided by the array length is zero.
Flowchart:

Sample Solution-2:
Python Code:
Sample Output:
Original array: 1 3 5 7 9 Check the average value of the elements of the said array is a whole number or not: True Original array: 2 4 2 6 4 8 Check the average value of the elements of the said array is a whole number or not: False
Explanation:
Here is a breakdown of the above Python code:
- Import Statement:
- The 'array' module is imported with the alias 'arr'.
- Test Function (test function):
- The "test()" function is defined to check if the average value of the elements in an array is a whole number.
- It calculates the average by dividing the sum of array elements by the array length and checking if the remainder is zero.
Flowchart:

Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to convert the letters of a given string (same case-upper/lower) into alphabetical order.
Next: Write a Python program to remove all vowels from a given string.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics