From fdab9638fee04c9272fe6ec1a2f5b4d87e3f9f56 Mon Sep 17 00:00:00 2001 From: Cori Peck Date: Mon, 9 Nov 2020 11:18:48 -0600 Subject: [PATCH 1/2] solves task 1 --- client3.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client3.py b/client3.py index f1771c3..ecfe6be 100644 --- a/client3.py +++ b/client3.py @@ -35,14 +35,17 @@ def getDataPoint(quote): stock = quote['stock'] bid_price = float(quote['top_bid']['price']) ask_price = float(quote['top_ask']['price']) - price = bid_price + price = (bid_price + ask_price) /2 return stock, bid_price, ask_price, price def getRatio(price_a, price_b): """ Get ratio of price_a and price_b """ """ ------------- Update this function ------------- """ """ Also create some unit tests for this function in client_test.py """ - return 1 + if (price_b == 0): + #when price_b is 0 avoid throwing ZeroDivisionError + return + return price_a/price_b # Main if __name__ == "__main__": @@ -52,8 +55,10 @@ def getRatio(price_a, price_b): quotes = json.loads(urllib.request.urlopen(QUERY.format(random.random())).read()) """ ----------- Update to get the ratio --------------- """ + prices = {} for quote in quotes: stock, bid_price, ask_price, price = getDataPoint(quote) + prices[stock] = price print ("Quoted %s at (bid:%s, ask:%s, price:%s)" % (stock, bid_price, ask_price, price)) - print ("Ratio %s" % getRatio(price, price)) + print ("Ratio %s" % getRatio(prices['ABC'], prices['DEF'])) From 14780efe15dfa3e4672644db79b3589af5638f7e Mon Sep 17 00:00:00 2001 From: Cori Peck Date: Mon, 9 Nov 2020 12:58:06 -0600 Subject: [PATCH 2/2] solves bonus task - tests --- __pycache__/client3.cpython-38.pyc | Bin 0 -> 1136 bytes client_test.py | 28 +++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 __pycache__/client3.cpython-38.pyc diff --git a/__pycache__/client3.cpython-38.pyc b/__pycache__/client3.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3b49a1e75486e42e0ff766bab10e0b64f21f13ed GIT binary patch literal 1136 zcmYjQ&2Aev5GHrI(#n=xH~v*~VG9JUfI4=NOCY3eQaLS9w1$(whY%_j>*dJWc(p5& zRGX;sNj>%<hdu(YJ>}k0(L;xnZG^=9ayUElarUIuS|Pap`1M`#UxSdpo$=v9 zA9;eL|3W5-qy-Vw%RmHPh9dNm2_^#($xzfJlhN-))MZW9QO3}a@p+*BgcVqY+MLem zA^G`@XhOJX0e!u;_z0rKI0pHkk+4XFp2%l5|?{u^)0Y{d8!| zxVyh!R9RXKD{Z=u4jvusUra!~{U(=R{dSrELkY={ZdZgFL+T;vC&*@qOPgF$gF#%TCLLFKX}FEFsj_ohH`O>f&83aTD$ihPr~3STfF*XQjRr-PnoeY+ zi%DfbIk#=#g=87uz}Tg#TzBt?T1D~i)2!P+(V%p{SE;=J!|_j*I!nvmFxAjEc;|uh z_4W*8!#!v3J=i;b^{}56Ih5w%{qbAdJOgux^&b0rF{$=L7shlQcay3X`Z8C~&2qXU z5Ah}{Gb$;LP*Vmk5#$-YOAxkj`WgQo3`a=v%7Nw^Nm8Dc@>)OT%01nY@1+xn`gO>S za_SG3tcig(##&#vd>yoO4H;o^z^GdDr%5tO^D;@MpFejXN`6oC)bKA5#_m1+CCC1~ z^q)bkGmU*VjI-g>Z+kX8eD+=E6R|c?MUkK0SAe6Yji@bc%S=83!CvdCv^9l&R3i~R zKY8}zm8C}>r`tlxbOcFaS&naMBaA%*OA{O6D@!fvH<|00xf%ne8&qnP8p{-<($@SC zXi@W(Y87L9ek7Fp<&}FNKL&o9O7j6sZYtCgtH&dp*#f@aLYL;qV(NFuLKei0cqI