Programming in Python – an illustrative example
In the previous sections, we discussed variable types and data containers. There are many more aspects of Python programming, such as control flow with if/else statements, loops, and comprehensions; functions; and classes and object-oriented programming. Commonly, Python programs are packaged into modules, which are self-standing scripts that can be run from the command line to perform computing tasks.
Let's introduce some of these concepts in Python with a "module" of our own (you can use the Jupyter Notebook for this):
from math import pow LB_TO_KG = 0.453592 IN_TO_M = 0.0254 class Patient: def __init__(self, name, weight_lbs, height_in): self.name = name self.weight_lbs = weight_lbs self.weight_kg = weight_lbs * LB_TO_KG self.height_in = height_in self.height_m = height_in * IN_TO_M def calculate_bmi(self): return self.weight_kg / pow(self.height_m, 2) def get_height_m(self...