Question

In Python Write code that creates and prints a list by multiplying each number in the...

In Python

Write code that creates and prints a list by multiplying each number in the nums array by the number that precedes it. If there’s no preceding number, use zero in place of the preceding number. You could solve this problem serveral ways, but in this case, you’re restricted to using a for loop. You might have to create a temporary storage variable in your solution.

Using another for loop, print the elements with a comma between them.

Your output should look something like this:

0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462, 506, 552, 600, 650, 702, 756, 812, 870, 930, 992, 1056, 1122, 1190, 1260, 1332, 1406, 1482, 1560, 1640, 1722, 1806, 1892, 1980, 2070, 2162, 2256, 2352, 2450, 2550, 2652, 2756, 2862, 2970, 3080, 3192, 3306, 3422, 3540, 3660, 3782, 3906, 4032, 4160, 4290, 4422, 4556, 4692, 4830, 4970, 5112, 5256, 5402, 5550, 5700, 5852, 6006, 6162, 6320, 6480, 6642, 6806, 6972, 7140, 7310, 7482, 7656, 7832, 8010, 8190, 8372, 8556, 8742, 8930, 9120, 9312, 9506, 9702, 9900, 
0 0
Add a comment Improve this question Transcribed image text
Answer #1
nums = [x for x in range(100)]

if len(nums) > 0:
    i = 1
    temp = nums[0]
    while i < len(nums):
        t = nums[i]
        nums[i] *= temp
        temp = t
        i += 1

    for i in range(len(nums)):
        print(nums[i], end='')
        if i == len(nums) - 1:
            print()
        else:
            print(', ', end='')
Add a comment
Know the answer?
Add Answer to:
In Python Write code that creates and prints a list by multiplying each number in the...
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