Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This sum_of_values_and_indices function accepts a lsit of numbers and returns the sum of the elements along with their index value
- def sum_of_values_and_indices(value):
- total = 0
- addition = []
- value2 = value.copy()
- total_sum = []
- for number in value:
- #print(value.index(number))
- addition.append(value.index(number))
- #print (addition)
- total_sum = [x + y for x, y in zip(value2, addition)]
- #print (total_sum)
- for i in total_sum:
- total += i
- return total
- print((sum_of_values_and_indices([5, 9, 3, 7])))
- print((sum_of_values_and_indices([])))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement