Question: This is using python 3.8, Please include docstring and keep the code clear and simple. This is for a 100 level CMPT class so in-depth
This is using python 3.8, Please include docstring and keep the code clear and simple. This is for a 100 level CMPT class so in-depth explanation would be helpful.
write the bodies of the functions. You will also find a test script named testing.py. It has a bunch of test cases pre-written for you. Read it carefully, Thank you!!!


testing.py

Also, use to_string() to help you test and debug your functions. (a) (6 points) Implement the function sumnc() (the nc suggests node chain). The interface for the function is: def sumnc (node_chain): Purpose: Given a node chain with numeric data values, calculate the sum of the data values. Pre-conditions: :param node_chain: a node - chain, possibly empty, containing numeric data values Post-condition: None Return :return: the sum of the data values in the node chain A demonstration of the application of the function is as follows: empty-chain = None chain - N.node (1, N.node (2, N.node (3))) print('empty chain has the sum', sumnc (empty-chain)) print('chain has the sum', sumnc (chain)) The output from the demonstration is as follows: empty chain has the sum 0 chain has the sum 6 import node as N def sumnc (node_chain): Purpose: Given a node chain with numeric data values, calculate the sum of the data values. Pre-conditions: iparam node_chain: a node-chain, possibly empty, containing numeric data values Post-condition: None Return :return: the sum of the data values in the node chain return None #### UNIT TEST CASE: sumnc #### test_item = "sumnCO" 3 5 6 data_in = None expected = 0 reason = 'Empty node chain' 8 9 result = a5q2.sumnc (data_in) if result != expected: print('Test failed: {}: got "{}" expected "{}" -- {}'.format(test_item, result, expected, reason)) 10 11 12 13 14 15 16 17 #### UNIT TEST CASE: sumnc() #### data_in = N.node(1) expected = 1 reason = 'node chain with one node! 18 19 20 result = a5q2.sumnc (data_in) if result != expected: print('Test failed: {}: got "{}" expected "{}" -- {}'.format(test_item, result, expected, reason)) 21 22 23 24 ####UNITTESTCASE..count chain #### data_in = N.node(1, N.node(-2)) expected = -1 reason = 'node chain with two nodes' 25 26 result = a5q2.sumnc (data_in) if result != expected: print('Test failed: {}: got "{}" expected "{}" -- {}'.format(test_item, result, expected, reason)) 27 28 29 30 31 32 33 34 35 #UNITTESTCASE:..count chain #### data_in = N.node(1, N.node(-2, N.node(3))) expected = 2 reason = 'node chain with three nodes' 36 37 38 39 40 result = a5q2.sumnc (data_in) if result != expected: print('Test failed: {}: got "{}" expected "{}" -- {}'.format(test_item, result, expected, reason))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
