Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi there! Read carefully please****: The first 4 pictures is the main question,5th one is a5q4_provided.py and the last 5 pictures are a5q4_testing.py file.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Hi there! Read carefully please****:

The first 4 pictures is the main question,5th one is "a5q4_provided.py" and the last 5 pictures are " a5q4_testing.py" file.

Please give me the full hand written answer of this question and a picture of your code. And make sure to answer all of its parts.

Please Solve it only if you're sure that your answer is 100% correct otherwise let any other person to solve it.

I need the Correct answer please otherwise I'll give dislike and report it to the Chegg authorities. Sorry for these words but I'm tired of getting lots of wrong answers lately.

Please answer it as soon as possible with clear hand writting and and picture of your code. Thank you so much for your time and effort! Will give Thumbs-up if everything is Alright! Tysm!

reason = 'node chain with three nodes' result =a5q4. sumnc (data_in) if result != expected: print("Test failed: \{\}: got " \{\} " expected " \{\}.{} '.format(test_item, result, expected, reason)) \#\#\#\# UNIT TEST CASE: count_in() \#\#\#\# test_item = "count_in()" chain_in = None value_in = None expected = reason = 'Empty node chain' result =a5q4. count_in(chain_id, value_in) if result 1= expected: print('Test failed: \{\} : got " \{\} " expected " \{\} " . \{\} '.format(test_item, result, expected, reason)) \#\#\#\# UNIT TEST CASE: count_in() \#\#\#\# chain_in =Nnode(1) value in =0 expected =0 reason = 'node chain. with one node, value not present' result =a5q4. count_in (chain_in, value_in) if result I= expected; print( "Test failed: \{\} : got " \{\} " expected " \{\} ".\{\} '.format(test_item, result, expected, reason)) \#\#\#\# UNIT TEST CASE: count_in() \#\#\#\# chain_in = N. node (7) value_in =7 expected =1 reason = 'node chain with one node, value present' result =a5q4. count_in (chain_in, value_in) if result 1= expected: print( "Test failed: \{\} : got " \{\} " expected " \{\} ".. \{\} '.format(test_item, result, expected, reason)) \#A UNIT TEST CASE: count_in() \#\#\# chain in =N, node ('one',.N. node ('two')) value in =7 expected =0 reason = "node chain with two nodes, value not present" result =a5q4. count_in(chain_in, value_in) if result I= expected: print("Test failed: \{\} ; got "\{ } " expected " \{\}{}, format(test_item, result, expected, reason)) In this question you'll write three functions for node-chains. On Canvas. you can find a starter file called a5q4. py. with all the functions and doc-strings in place, and your job is to write the bodies of the functions. You will also find a test script named a5q4_testing.py. It has a bunch of test cases pre-written for you Read it carefully! Also, use to_string () to help you test and debug your functions. (a) (6 points) Implement the function sumic () (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 Post condition: Noneric data values Potone 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 oulput from the demonstration is as follows: empty chain has the sum 0 chain bas the sum 6 def count_in(node_chain, value): n n n Purpote: Counts the number of times a value appears in a node chain Pre - conditions: : param node_chain: a node chain, possibly empty : param value: a data value Roturn: : return: The number times the value appeare 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(1))) print ('empty chain has', count_in(ompty_chain, 1), 'occurrences of the valle Pint ('chain has', count_in(chain, 1), 'oceurrences of the value 1') The output from the demonstration is as follows. empty chain has 0 occurrences of the value 1 chain has 2 oecurrences of the value 1 A demonstration of the application of the function is as follows number, course number and instrions of the three functions. Be sure to include your name, NSID, student Evaluation - 6 marks: Your function sumnc(): - Uses the Node ADT to sum the data values in the chain correctly. - Works on node-chains of any length. - If your function uses for-loops. Python lists, or the Python sua() function, you will get ZERO marks. - 6 marks: Your function count_in(): - Uses the Node ADT to count ine data values in the chain correctly. - Works on node-chains of any length. - II your function uses for-loops, or Python lists, you will get ZERO marks. - 6 marks: Your function replace_in(): - Uses the Node ADT to replace the data values in the chain correctly. - Works on node-chains of any length. - Does not create any new nodes. - II your function uses for-toops, or Python lists, you will get ZERO marks. def sumnc(node_chain): nwa 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 n. :return: the sum of the data values in the node chain return None def count_in(node_chain, value): "II" Purpose: Counts the number of times a value appears in a node chain Pre-conditions: :param node_chain: a node chain, possibly empty : param value: a data value Return: :return: The number times the value appears in the node chain return None def replace_in(node_chain, target, replacement): Purpose: Replaces each occurrence of the target value with the replacement Pre-conditions: :param node_chain: a node-chain, possibly empty :param target: a value that might appear in the node chain :param replacement: the value to replace the target Pre-conditions: Each occurrence of the target value in the chain is replaced with the replacement value. Return: None import a5q3 as a5q3 import a5q4 as a5q4 import node as N \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \#\#\#\# UNIT TEST CASE: sumnc() \#\#F\# test_item = "sumnc()". data_in = None expected =0 reason = 'Empty node chain' result =a5q4. sumnc (data_in) if result I= expected: print("Test failed: \{\}: got " \{\} expected " }}{}. format(test_item, result, expected, reason)) H\#A\# UNIT TEST CASE: count chain() \#AH\# data_in =Nnode(1,Nnode(2)) expected =1 reason = 'node chain with two nodes: result =a5q4. sumnc (data_in) if result I = expected: print ('Test failed: {{}: got " \{\}" expected. " \{\}".{}. format(test_item, result, expected, reason)) H\#H\# UNIT TEST CASE: count_chain() \#H\#\# data. in =N,node(1,Nnode(2,N, node(3))) expected =2 \#\#\#\# UNIT TEST CASE: count_in() \#\#\#\# chain_in =N. node ('one', N. node ('two')) value_in = 'two' expected =1 reason = 'node chain with two nodes, value present last' result =a5q4. count in(chain in, value in) if result 1= expected: print('Test failed: \{\}: got " \{\} expected " \{\}{}.format (test_item, result, expected, reason)) \#\#\#\# UNIT TEST CASE: count in( ) \#\#\#\# chain in =N. node ('one ,N.node ( 'two ') ) value in = one expected =1 reason = 1 node chain with two-nodes, value present first' result =a5q4. count in(chain_in, value in) if result 1= expected: print ('Test faled: ={}: got " \{\} expected " \{\}{} format(test_item, result, expected, reason)) \#\#\#\#UNIF TEST CASE: count in() \#\#\#\# chatn in = N. node(True, = N.node (True)) value in = True expected=2 reason = "node chain with two nodes, value present twice' result =a5q4. count in (chain_in, value_in) if result I= expected: print('Iest failed: \{\} : got " \{\} expected "\{ }={}. format (test_item, result, expected, reason)) \#\#\#\# UNIT TEST CASE: count_in () \#\#\#\# chain_in =Nnode(1,N.node( 'two', N. node (1,NNode(tihreeT,Nnode(1))))) value in =1 expected =3 reason = 'node chain with three nodes, =value present multiple times' result =a5q4. count in (chain_in, value_in) if result I= expected: print('Test failed: \{\}: got " \{\} expected 11{}{}f format(test_item, result, expected, reason)) \#\#\#\# UNIT TEST CASE: count_in( ) \#\#\#\# chain_in =N.node(1,Nnode( 'two ,Nnode(3,Nnode( 'four' ), N ) ) value_in =555 expected =0 reason = 'node chain with four nodes, value not present' result =a5q4. count in (chain_in,_value_in) if result I expected: \#\#\# UNIT TEST CASE: replace_in() \#\#\#\# chain_in =Nnode(1) target in =1 repl_in =0 expected_str = " [/]n reason = 'node chain with one node, target replaced' a5q4.replace_in(chain_in, target_in, replin) result_str =a5q3.to_string(chain_in) if result_str t= expected str: print('Test failed: \{\}: got "\{\} expected " \{\} _. \{\} '.format (test_item, result_str, expected_str,_reason)) \#\#\#\# UNIT TEST CASE: replace in () HAth chain_in =N.node (1) target in = repl_in =1 expected_str = m [1/]11 reason = 'node chain with one node,target not present' a5q4. replace_in(chain_in, target_in, rep]_in) result_str =a5q3. to_string(chaininin) if result_str i= expected_str: print ('Test failed: \{\} : got " \{\} expected "Y" - \{\}.format(test_item, result_str, expected_str, reason)) \#\#HA UNIT TEST CASE: replace_in() \#HH chain_in =N. node (1,N. node (2)) target in =0 replin =1 expected_str ="[1][211] reason = 'node chain with two nodes, target not present' a5q4, replace in (chain_in, target_in, repl_in) result_str =a5q3, to string(chain_in) if result str 1= expected str: print ('Test failed: \{\} : got "\{\}" expected "\{\}" . \{\} ..format(test_item, result_str, expected_str, reason)) \#\#\#\# UNIT TEST CASE: replace_in() \#\#\#\# chain in =Nnode(1,NNode(2)) target in =1 repl in =10 expected str ="[10. ][211] reason = 'node chain with two nodes, target present first: a5q4.replace_in(chain_in, target_in, repi_in) result_str =a5q3. to_string(chain_in) if result_str = expected_str: print ('Test failed: \{\} : got "\{\}" expected "\{\} { ef \{\},{ format (test_item, result_str, expected_str, reason)) \#\#A\#\# UNIT TEST CASE: replace_in() HEA: chain_in =Nnode(1,Nnode(2)) target_in =2 repl_in =10 expected_str ="[1.1][10 l , ] ]" reason =' node chain with two nodes, target present lasti a5q4, replace_in(chain_in, target_in, repilin) result_str = a5q3, to_string(chain_-in) if result_str I = expected_str: print ('Test failed: {} : got "\{j expecteo "{} gof \{\} formatctest_item, result_str, expected_str, reason)\} \#\#\#\# UNIT TEST CASE: replace_in(s) H= target_in =1 replin =10 expected_str ="[10reason=] reason = 'node chain with multiple hodes, itarget present multiple times' a5q4,replace_in (chain_in, target_in hepitin) result_str = asq3. to_string (chaintinf) if result_str I = expected_str: print ('Test failed: \{\} got of { gexpected \{\},f} f format (test_item, result_str, expected_str, reason)) \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# print (x testing complete )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

Students also viewed these Databases questions

Question

Describe the factors influencing of performance appraisal.

Answered: 1 week ago