Final General Python
docx
keyboard_arrow_up
School
Binghamton University *
*We aren’t endorsed by this school
Course
311
Subject
Industrial Engineering
Date
Jan 9, 2024
Type
docx
Pages
2
Uploaded by JusticeJellyfish31029
PYTHON SECTION
Question 1 (5 points)
Define a function called “max_loan”. This function takes one input (
current_amt
) and tells you
how much you can borrow on a blockchain lending application. The function should print and
return
the maximum size of a loan you can receive, given your current amount of money
(
current_amt
). Assume that the collateralization ratio for borrowing is 1.5. This means that for
every $1 you borrow, you must supply $1.5. max_loan (750) should print and return
the value 500.0
Use a print statement to explain how this function applies topics studied in our class.
Question 2 (5 points)
Define a function called “max_loan_vol”. This function takes two inputs (
current_amt,
volatility
) and tells you how much you can borrow on a blockchain lending application. The
function should print and return
the maximum size of a loan you can receive, given your
current amount of money (
current_amt
) and its volatility (
volatility
). Assume that the
collateralization ratio is 1.25 * (1 + volatility). This means that for every $1 you borrow, you
must supply $1.25 if the volatility is 0. If the volatility is 0.25, you must supply 1.25 * (1 + 0.25)
for every $1 you borrow.
max_loan(1000, 0.25) should print and return
the value 640.0
Use a print statement to explain how this function applies topics studied in our class. Why should
volatility be an important input to determine how much you can borrow?
Question 3 (5 points)
Define a function called “dex”. This function takes three inputs (
dai, eth, exchange)
and tells you
how the liquidity pools of the dex change in response to someone exchanging ETH for DAI
using the constant product rule. dai is the amount of DAI in the liquidity pool before the
exchange happens. eth is the amount of ETH in the liquidity pool before the exchange happens.
exchange is the amount of ETH that a trader is providing to the liquidity pool in exchange for
DAI. The function should print the following:
The old liquidity pool had xxx ETH and xxx DAI
You exchanged xxx ETH for xxx DAI
The new liquidity pool has xxx ETH and xxx DAI
dex(5000, 300, 50) should print ‘The old liquidity pool had 300 ETH and 5000 DAI’
‘You exchanged 50 ETH for 714.2857142857147 DAI’
‘The new liquidity pool has 350 ETH and 4285.714285714285 DAI’
Use a print statement to explain how this function applies topics studied in our class.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help