Answered step by step
Verified Expert Solution
Question
1 Approved Answer
L 4 - template.py: # Turn diagnostics on / off by setting VERBOSE True / False . VERBOSE = True def L 4 ( inString
Ltemplate.py:
# Turn diagnostics onoff by setting VERBOSE TrueFalse
VERBOSE True
def LinString:
# inString is a whitespace delimited list of string representations
# of decimal ints. For example, is a valid inString.
#
# For lab # add code to L that parses inString and computes the
# count of positive ints equal to mod as well as storing the
# last negative int.
#
# If inString contains a whitespace delimited substring of symbols that
# is not a valid decimal int, LinString returns no;
# else if inString does not contain any negative ints, LinString
# returns no;
# else if the count of positive ints equal to mod does not match
# the absolute value of the last negative int, LinString returns no;
# else LinString returns 'yes'.
#
# For example, if inString LinString would
# return 'yes' because inString contains two positive ints equal to
# mod and and the absolute value of the last negative int
# in inString is ; if inString LinString
# returns no because there is only one positive int equal to mod
# not ; if inString LinString returns no
# because inString does not contain any negative int; and if inString
# xF LinString returns no because xF is not
# a valid representation of a decimal int.
#
# Do not insert any print statements into this function. If you want to
# show the result, print the return value.
return 'yes'
if namemain:
def testcaseFstring,expected,num,comment:
err
result Fstring
funcname strFsplit
funccall ffuncnamestring
if result expected: err
e expected
print ferrtest #numfunccall: expected e received
result
print ftest #num Explanation: comment
return num
num
s
exp positive ints is the last negative int'
num testcaseLs'yes',num,exp
s
exp 'Only one positive int equal to mod not
num testcaseLsnonum,exp
s
exp no negative ints'
num testcaseLsnonum,exp
s xF
exp xF is not a valid representation of a decimal int'
num testcaseLsnonum,exp
Modify the attached program Ltemplate.py to create a SISO String In String Out Python decision function with the following properties:
The expected input parameter inString is a string encoding integers delimited by white space. For example, is a valid inString.
The function L should parse inString and compute the count of positive ints equal to mod as well as storing the last negative int. Note that the Python mod operator is and thus these expressions all evaluate to True: ;
If inString contains a whitespace delimited substring of symbols that is not a valid decimal int, LinString returns no;
else if inString does not contain any negative ints, LinString returns no;
else if the count of positive ints equal to mod does not match the absolute value of the last negative int, LinString returns no;
else LinString returns 'yes'.
Lpy comes with a test harness initialized with test cases. Executing L prints a handcoded explanation for the expected results, and flags unexpected results with The template just returns 'yes' for all inputs, resulting in this output:
test # L: expected "yes", received "yes"
test # Explanation: positive ints is the last negative int
test # L: expected no received "yes"
test # Explanation: Only one positive int equal to mod not
test # L: expected no received "yes"
test # Explanation: no negative ints
test # L xF : expected no received "yes"
test # Explanation: xF is not a valid representation of a decimal int
A correct implementation would return no for test cases and while still returning 'yes' for test case
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started