<jupyter_start><jupyter_text>Week 3 - FunctionsThe main objective for this part of the lecture is to develop an understanding of:* What is a function?* How can functions be used?* Why is using functions a good idea?  Build-In Functions<jupyter_code>help(pow)
pow(3, 3)
id(pow)
id(3)<jupyter_output><empty_output><jupyter_text>Creating our own functions<jupyter_code>def BMI ( weight_kg, height_cm ):
    height_m = height_cm / 100
    bmi = weight_kg / (height_m ** 2)
    return bmi
power=2
BMI (90.7, 182)
height_m = 98
height_m<jupyter_output><empty_output><jupyter_text>Adding documentation<jupyter_code>def BMI ( weight_kg, height_cm ):
    """ (float, float) -> float
    
    Returns the BMI calculated by dividing weight in kilograms by the square of the height in meters squared.
    
    >>> BMI (90.7, 182)
    27.38195870064002
    """
    height_m = height_cm / 100
    bmi = weight_kg / (height_m ** 2)
    return bmi
help(BMI)
def doSometing(a):
    """ (string) -> string
    This function does something great!
    
    >>> doSomething(a)
    Magic!!!
    """
    return 'Magic!!!'<jupyter_output><empty_output><jupyter_text>Another functionLet's right a new function that calculates the drip rate for an IV drip as in the following example:Imagine that you have a 1,000 mL IV bag and need to infuse 125 mg of ABC at a rate of 5 mg per hour.  Assuming you use entire bag to deliver the dose of ABC, what should the drip rate be (mL per hour) in order to deliver the entire IV bag.<jupyter_code>def drip_rate ( med_dose, med_per_time, bag_size ):
    """ (int, int, int) -> float
    Returns the drip rate using the units of volume from bag_size and the unit of time from the med_per_time parameter.
    
    >>> drip_rate ( 10, 1, 10 )
    1.0
    """
    time = med_dose / med_per_time
    drip_rate = bag_size / time
    return drip_rate 
help(drip_rate)
drip_rate ( 125, 5, 1000 )
drip_rate ( 10, 1, 10 )
drip_rate ( med_per_time = 5, med_dose = 125, bag_size = 1000 )
l = [[125,5,1000],[10,1,10]]
for item in l:
    print(drip_rate(item[0],item[1],item[2]))<jupyter_output>40.0
1.0
StarcoderdataJupyterStructuredCleanDedup