Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions prometheus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def calculate_sum(my_list: list[int]) -> int:
"""
Calculates the sum of a list of integers, where each number is multiplied by its index before being added to the sum.

:param my_list: List of integers
:return: Sum of integers multiplied by their index
"""
if not isinstance(my_list, list):
raise TypeError("Input must be a list")

return sum(index * num for index, num in enumerate(my_list, start=1))


# Example usage
example_list_1 = [1, 2, 3, 4]
example_list_2 = [0, -1, 2, -3]

print(calculate_sum(example_list_1)) # Output: 30
print(calculate_sum(example_list_2)) # Output: -5