Claudio Pedrazzi

Concerning the question about getting the maximum value, if I understand correctly, the problem is that everytime you go through the loop, you overwrite my_energy.  I would simply use an additional storage variable like max_my_energy and initialise it to 0 before the loop begins, then in every step you should simply compare my_energy with the maximum until there, and if higher, substitute it.