Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help correcting how to break a string into parts. I had to modify a lot of lines to make sure it wasn't more

I need help correcting how to break a string into parts.

I had to modify a lot of lines to make sure it wasn't more than 80 characters. I need help fixing this.

import introcs

APIKEY = 'a1b2c3d4' (This is a sample key. my key has more characters in it).

def service_response (src, dst, amt):

"""

Returns a JSON string that is a response to a currency query.

A currency query converts amt money in currency src to the currency dst. The response

should be a string of the form

'{"success": true, "src": "", dst: "", error: ""}'

where the values src-amount and dst-amount contain the value and name for the src

and dst currencies, respectively. If the query is invalid, both src-amount and

dst-amount will be empty, and the error message will not be empty.

There may or may not be spaces after the colon.To test this function, you should

chose specific examples from your web browser.

Parameter src: the currency on hand

Precondition src is a nonempty string with only letters

Parameter dst: the currency to convert to

Precondition dst is a nonempty string with only letters

Parameter amt: amount of currency to convert

Precondition amt is a float or int

"""

#introcs.isalpha checks if src is a nonempty string with only letters

assert introcs.isalpha(src), repr(src) + ' is not a string.'

#introcs.isalpha checks if dst is a nonempty string with only letters

assert introcs.isalpha(dst), repr(dst) + ' is not a string.'

#check if the type of amt is float or int, print message if not

assert type(amt) == float or type(amt) == +\ Not sure if this is the correct way to break a string into smaller parts.

int, repr(amt) + ' is not a float nor an integer.'

x= ('https://ecpyfac.ecornell.com/python/currency/fixed?src='+str(src) +\

'&dst='+str(dst)+'&amt='+str(amt))+"&key=a1b2c3d4"

return introcs.urlread(x)

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Which event marked the official end of the American civil war ?

Answered: 1 week ago