Python version of CA homework