To compute the sum, maximum, and minimum of a list of numbers in Python, you can use built-in functions and methods. Here are examples of how you can accomplish this:
- Computing the sum:
my_list = [1, 2, 3, 4, 5]
sum_of_list = sum(my_list)
print("Sum:", sum_of_list)
In this example, the sum()
function is used to calculate the sum of all the numbers in the list. The result is stored in the sum_of_list
variable and then printed.
- Computing the maximum:
my_list = [1, 2, 3, 4, 5]
max_of_list = max(my_list)
print("Maximum:", max_of_list)
Here, the max()
function is used to find the maximum value in the list. The maximum value is stored in the max_of_list
variable and then printed.
- Computing the minimum:
my_list = [1, 2, 3, 4, 5]
min_of_list = min(my_list)
print("Minimum:", min_of_list)
Similarly, the min()
function is used to find the minimum value in the list. The minimum value is stored in the min_of_list
variable and then printed.
By using these built-in functions, you can easily compute the sum, maximum, and minimum of a list of numbers in Python. Remember to adjust the variable names and adapt the code to your specific use case as needed.
+ There are no comments
Add yours