Sobes.tech
Junior — Senior

Improving the readability and efficiency of the summation function

livecode

Task condition

Make the code more understandable by replacing inefficient constructs, and check that there are no errors or potential issues in it.

def sum_and_display(arr):
    total_sum = 0
    for idx in range(len(arr)):
        total_sum += arr[idx]
    print("The sum is: " + str(total_sum))

numbers = [1, 2, 3, 4, 5]
sum_and_display(numbers)