Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem: Fill a list of ints (list<int>) called nlist with 10 random numbers in

ID: 3768690 • Letter: P

Question

Problem:

Fill a list of ints (list<int>) called nlist with 10 random numbers in the range [-10,10]. Find all numbers in nlist that add up to 0. That is your program should produce a list<list<int>> nlists where each element of nlists is itself a list<int> and the sum of the elements in each list is 0. Output your result in a nice clean way, so I can clearly tell what each of the lists are.

Example:

nlist is {-2,7,2,9,-5,-3,10,-4,0}

Your program might produce the output:

{0}

{-2,2}

{-2,-5,7}

{-3,-4,7}

{-2,-5,-3,10} {9,-5,-4}

Note: It is possible that in some particular list no numbers add up to 0.

Explanation / Answer

nlist ={-2,7,2,9,-5,-3,10,-4,0}
nlist_second = [-1,6, 7, 8, 9, 10,3,1,0]
nlist_third = [ ]

a = len(first)
b = int(0)
while True:
    x = first[b]
    y = nlist_second[b]
    nlist_Answer = x + y
    nlist_third.append(nlist_Answer)
    b = b + 1
    if b == a:
        break

print nlist_third

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote