Question: I continue to work on an assignment and I have another problem that has taken much time to overcome without success. The question is as

I continue to work on an assignment and I have another problem that has taken much time to overcome without success. The question is as follows:
22. Implement the Function get_src
Implement the function according to the specification. An ideal solution will use first_inside_quotes as a helper. Use the test script testcurrency.py to aid your development before checking your answer below.
My answer is:
pos1= introcs.find_str(json,'"')
pos2= introcs.find_str(json,'",', pos1+25)
return json[pos1+25:pos2]
I get the following error message:
Call get_src('{"success": false, "src": "","dst": "", "error": "The rate for currency EUF is not present."}') returned '"', not the expected ''.
Another answer based on an answer from your experts on a previous occasion is:
def get_src(json):
"""
Returns the src value in the response to a currency query.
Given a JSON string provided by the web service, this function returns
the string inside string quotes (") immediately following the substring '"src"'.
For example, if the json is '{"success": true, "src": "2 United States Dollars",
"dst": "1.772814 Euros", "error": ""}', then this function returns
'2 United States Dollars' (not '"2 United States Dollars"').
On the other hand, if the json is '{"success": false, "src":"","dst":"",
"error":"Source currency code is invalid."}', then this function returns
the empty string.
Parameter json: a json string to parse
Precondition: json is a string provided by the web service (ONLY enforce the type)
"""
start = json.find('"src"')+ len('"src"')+1 # Find the starting index of the value
end = json.find('"', start) # Find the ending index of the value
return json[start:end] # Extract and return the value between the quotes
I get the following error message:
Call get_src('{"success": true, "src": "2.5 United States Dollars", "dst": "2.28242 Euros", "error": ""}') returned '', not the expected '2.5 United States Dollars'.
I also tried the following:
start = json.find('"src"')+ len('"src"')+3 # Find the starting index of the value
end = json.find('"', start) # Find the ending index of the value
return json[start:end] # Extract and return the value between the quotes
I still get the error following message:
Call get_src('{"success":true, "src":"2.5 United States Dollars", "dst":"2.28242 Euros", "error":""}') returned '.5 United States Dollars', not the expected '2.5 United States Dollars'.
It is interesting that even your answer- from a previous occasion - still gives an error message. I would appreciate your help as I have wasted sufficient time on this. Thank you...
I continue to work on an assignment and I have

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 Programming Questions!