global_var = "global"def my_func(): local_var = "local" print(global_var) # Can read global variable print(local_var) # Local variablemy_func()# print(local_var) # NameError: cannot access outside the function
Docstring
def calculate_bmi(weight, height): """Calculates BMI. Args: weight: Weight in kg height: Height in meters Returns: BMI value (float) """ return weight / (height ** 2)
Today’s Exercises
Write a function that finds the greatest common divisor (GCD) of two numbers.
Write a function that returns the mean, variance, and standard deviation of a list.
Create a temperature conversion function (Celsius to Fahrenheit and vice versa, with direction as a parameter).