PracticeArrays

Total the Warehouse Registry Values

BeginnerArraystraversalaccumulationstate tracking Time not estimated Not started

Context

A logistics company keeps a shipment registry mapping internal shipment codes to package weights. The registry system supplies its stored numeric values as an array, while the codes are omitted because they do not affect the calculation. Find the combined weight of all registered shipments.

Problem

Implement a function that returns the total of every value in the given shipment registry. Start with the additive identity, inspect each value exactly once, and add it to a running total. The registry may contain no shipments, zero weights, negative adjustments, or large values within the stated limits. Return the final total after all values have been processed.

Examples

Example 1
Input: values = []
Output: 0
Explanation: The empty registry returns 0. (fact_ids:, )
Example 2
Input: values = [12, 0, 7, 0]
Output: 19
Explanation: The values 12, 0, 7, and 0 produce a returned total of 19. (fact_ids:, )
Example 3
Input: values = [25, -8, 13, -5]
Output: 25
Explanation: The values 25, -8, 13, and -5 produce a returned total of 25 after signed contributions are accumulated. (fact_ids:, )

Constraints

  • 0 <= len(values) <= 100
  • -1000000 <= values[i] <= 1000000 for every i
  • Types: values is int[]; result is int

Function signature

def sum_registry_values(values: list[int]) -> int
values list[int]
Numeric values stored in the shipment registry, in any order.
returns int
The sum of every value in values, or 0 when the registry is empty.

Adapted from MBPP problem task_796 (CC BY 4.0). Rewritten, extended and verified by Iksha.

Approved · c004r1-abs_196_v214 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1