Given an array of integers, can you find the sum of its elements?
The first line contains an integer, N, denoting the size of the array.
The second line contains N space-separated integers representing the array's elements.
Print the sum of the array's elements as a single integer.
1 2 3 4 10 11
n = int(input().strip())
arr = [int(arr_temp) for arr_temp in input().strip().split(' ')]
while i < n:
total += arr[i]
The code listed above may or may not be the "best" solution. Please be advised that this is just the way I did it. There are normally thousands of different ways to solve the same programming problem. Find an error? Let me know in the contact form below.
Feel free to email me feedback, suggestions, notes, or to just say hello!