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

organize and discuss how to do verification and validation of the following code

ID: 3726742 • Letter: O

Question

organize and discuss how to do verification and validation of the following code:

numbers = [[4, 3], [1,2], [154,233], [555,-444]]

def show_add_pair(pair):
    print str(pair[0]) + '+' + str(pair[1]) + '= ' + str(pair[0] + pair[1])

print ' Part 1'
print '4+3=',4+3
print '1+2=',1+2
print '154+233=',154+233
print '555+-444=',555+(-444)

print ' Part 2'
show_add_pair(numbers[0])
show_add_pair(numbers[1])
show_add_pair(numbers[2])
show_add_pair(numbers[3])

print ' Part 3'
for n in numbers:
    show_add_pair(n)

print ' Part 4'
map(show_add_pair, numbers)

Explanation / Answer

Firstly numbers = [[4, 3], [1,2], [154,233], [555,-444]],

it means numbers is a list, It has indexes i.e., 0,1,2,3,...

means numbers[0] is [4,3], numbers[1] = [1,2], numbers[3] = [555, -444], etc...

In Part1: It's just addition of two numbers only

In Part2: we are passing each sub list to the function

i.e., show_add_pair([4,3])

show_add_pair([1,2]), etc...

In Part3: As like Part 2. In this instead of sending manual, we are passing automatically using for loop.

In Part4: It is map, It is also work like as in part 3. map is pre defined function executes all the elements are complete...

All are same but we are reducing steps to make easier...