Advertisement
ganiyuisholaafeez

Total Sum of Values and Indices

Feb 22nd, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. """ The function that sums and returns all the values and indices
  2. of a list of numbers"""
  3. # This is achievable using the enumerate()
  4. def sum_of_values_and_indices(values):
  5.     total = 0           # The base total
  6.     altogether = total  # Base Total of the Results
  7.     for index, value in enumerate(values):
  8.         total = index + value
  9.         altogether += total
  10.         print(f"{index} + {value} = {total}")
  11.     print(f"Altogether, the total of the results = {altogether}")
  12.        
  13.  
  14. sum_of_values_and_indices([1, 2, 3]) # 9
  15. sum_of_values_and_indices([0, 0, 0, 0]) # 6
  16. sum_of_values_and_indices([]) # 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement