Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ The function that sums and returns all the values and indices
- of a list of numbers"""
- # This is achievable using the enumerate()
- def sum_of_values_and_indices(values):
- total = 0 # The base total
- altogether = total # Base Total of the Results
- for index, value in enumerate(values):
- total = index + value
- altogether += total
- print(f"{index} + {value} = {total}")
- print(f"Altogether, the total of the results = {altogether}")
- sum_of_values_and_indices([1, 2, 3]) # 9
- sum_of_values_and_indices([0, 0, 0, 0]) # 6
- sum_of_values_and_indices([]) # 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement