OsahonE

Wk4_7

Mar 31st, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. def sum_of_values_and_indices(list):
  2.     total_sum = 0
  3.    
  4.     '''iterating over the list and summing all
  5.     values in the list along with their index
  6.     positions, we have:'''
  7.    
  8.     for values in list:
  9.         total_sum += values + list.index(values)
  10.         '''total_sum = total_sum + values +
  11.         list.index(values)'''
  12.        
  13.     return total_sum
  14.    
  15. print(sum_of_values_and_indices([1, 2, 3]))
  16. print(sum_of_values_and_indices([8, 7]))
Add Comment
Please, Sign In to add comment