exercise from AbsoluteC++/AbsoluteJava by Walter Savitch done in Python