"""The tower of Hanoi."""
from __future__ import print_function


def move_towers(height, from_pole, to_pole, with_pole):
    if height == 1:
        print('Moving disk from {0} to {1}'.format(from_pole, to_pole))
    else:
        move_towers(height - 1, from_pole, with_pole, to_pole)
        move_towers(1, from_pole, to_pole, with_pole)
        move_towers(height - 1, with_pole, to_pole, from_pole)  


def main():
    from_pole = 'f' 
    to_pole = 't'
    with_pole = 'w'

    height = 1
    print('height: {}'.format(height))
    move_towers(height, from_pole, to_pole, with_pole)

    height = 2
    print('height: {}'.format(height))
    move_towers(height, from_pole, to_pole, with_pole)

    height = 5 
    print('height: {}'.format(height))
    move_towers(height, from_pole, to_pole, with_pole)

if __name__ == '__main__':
    main()

"""The tower of Hanoi."""
from __future__ import absolute_import
from __future__ import print_function
from __future__ import division


def tower_of_hanoi(height, from_pole, to_pole, with_pole, counter):
    if height == 1:
        counter[0] += 1
        print('{0} -> {1}'.format(from_pole, to_pole))
    else:
        tower_of_hanoi(height - 1, from_pole, with_pole, to_pole, counter)
        tower_of_hanoi(1, from_pole, to_pole, with_pole, counter)
        tower_of_hanoi(height - 1, with_pole, to_pole, from_pole, counter)  


def main():
    from_pole = 'A' 
    to_pole = 'B'
    with_pole = 'C'

    height = 1
    counter = [0]
    print('height: {}'.format(height))
    tower_of_hanoi(height, from_pole, to_pole, with_pole, counter)
    print('counter: {}'.format(counter[0]))

    height = 2
    counter = [0]
    print('height: {}'.format(height))
    tower_of_hanoi(height, from_pole, to_pole, with_pole, counter)
    print('counter: {}'.format(counter[0]))

    height = 5
    counter = [0]
    print('height: {}'.format(height))
    tower_of_hanoi(height, from_pole, to_pole, with_pole, counter)
    print('counter: {}'.format(counter[0]))


if __name__ == '__main__':
    main()

Revise tower of hanoi alg from Yuanlin