Question: The input parameter to L 0 6 0 4 b ( inString ) is expected to be a white - space delimited list of string

The input parameter to L0604b(inString) is expected to be a white-space delimited list of string representations of decimal ints. For example, '765-24' is a valid inString.
If inString contains a substring that is not white space or a valid decimal int, L0604b(inString)=='no'. For example, L0604b('7-65-2 x0F 8)
'=='no', because x0F is not a valid decimal int.
Otherwise, if inString does not contain a substring representing positive int, return 'no'. For example, L0604b('-2')=='no'.
Otherwise, L0130b(inString) should return a string representing the sum of all positive ints in inString, mod 2. For example,L0604b('765-29') would return '1', because 7+6+5+9=27, and 27%2==1.(Note that % is the Python mod operator.)
Download L0604b-template.py Download L0604b-template.py, and modify it to implement the required logic.
L0604b-template.py:
def L0604b(inString):
# inString is a white-space delimited list of string representations
# of decimal ints. For example, '765-24' is a valid inString.
# If inString contains a white-space delimited substring of symbols that
# is not a valid decimal int, L0604b(inString)=='no'. For example,
# L0604b('7-65-2 x0F 8)'=='no', because 'x0F' is not a valid
# decimal int.
# Otherwise, if inString does not contain any representations of positive
# ints, return 'no'
# Otherwise, L0604b(inString) returns the sum of all positive ints mod 2.
# For example,L0604b('765-25') would return 1, because
# 7+6+5+9=27,27%2==1.(Note that % is the Python mod operator.
#
# Add the needed code.
#
return '0' # returning a constant value will not work.
if __name__=='__main__':
def test_case(F,string,expected,num,comment=''):
err ='**'
result = F(string)
func_name = str(F).split()[1]
func_call = f'''{func_name}("{string}")'''
if result == expected: err =''
e = expected
print (f'{err}test #{num}{func_call}: expected "{e}", received
"{result}"')
print (f'test #{num} Explanation: {comment}
')
return num +1
F = L0604b
num =1
s ='1059-2'
exp ='10+5+9=24,24%2=0'
num = test_case(F,1,'0',num,exp)
s ='-2'
exp ='No positive ints'
num = test_case(F,s,'no',num,exp)
s ='7-5162'
exp ='7+16+2=25,25%2=1'
num = test_case(F,s,'1',num,exp)
s ='x1611011-2'
exp ="x1 does not represent a decimal int"
num = test_case(F,s,'14',num,exp)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!