Question

Define a function add_nums_x_pos_given_list_nums (..) which receives a list that is guaranteed to only have numbers...

Define a function add_nums_x_pos_given_list_nums (..) which receives a list that is guaranteed to only have numbers (or the empty list) and returns the sum of each number multiplied by the position where the number is. (In the case of the empty list the function it will return 0)

For example add_nums_x_pos_given_list_nums ([10,20,30]) will return the value 80 which is the result of adding:

0 * 10 (10 is in position 0 in the list)

+ 1 * 20

+ 2 * 30

As an example, the following code fragment:

res = add_nums_x_pos_given_list_nums ([10,20,30]) print(res)

should produce the output:

80

langauge python

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def add_nums_x_pos_given_list_nums(listst):
return sum(i * j for i, j in enumerate(listst))

listst=[ 10,20,30]
result=add_nums_x_pos_given_list_nums(listst)
print(result)

Add a comment
Know the answer?
Add Answer to:
Define a function add_nums_x_pos_given_list_nums (..) which receives a list that is guaranteed to only have numbers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT