We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 48ebe7b commit 347d8e8Copy full SHA for 347d8e8
python_programs/alternate_pair_sum.py
@@ -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