Skip to content

Commit 347d8e8

Browse files
authored
Add files via upload
1 parent 48ebe7b commit 347d8e8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

python_programs/alternate_pair_sum.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def calculate_pairs(arr):
2+
# Iterate through the array by steps of 2
3+
for i in range(0, len(arr), 2):
4+
# Check if the pair is complete
5+
if i + 1 < len(arr):
6+
print(f"Index {i} + Index {i+1}:", arr[i] + arr[i+1])
7+
else:
8+
# If the last element doesn't have a pair, print it as it is
9+
print(f"Index {i}:", arr[i])
10+
11+
# Example usage:
12+
arr = [1, 2, 3, 4, 5]
13+
calculate_pairs(arr)

0 commit comments

Comments
 (0)