To find the range of all elements in an array in Python, we can use the min()
and max()
functions to find the minimum and maximum values in the array, respectively. Then, we can subtract the minimum from the maximum to get the range of the array.
Here's an example code snippet that demonstrates how to find the range of all elements in an array in Python:
main.py222 chars9 lines
Output:
main.py29 chars2 lines
In this example, we define a function called find_range()
that takes an array as input and returns the range of the array. We use the min()
function to find the minimum value in the array, and the max()
function to find the maximum value in the array. We then subtract the minimum from the maximum to get the range of the array. Finally, we define an array called my_array
and call the find_range()
function with my_array
as input, and print the result.
gistlibby LogSnag