Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 137
  • Last Modified:

h1,2,3 but can not see these values in a debugger

    def hanoi(n,s,t,b):
        assert n > 0
        if n == 1:
            print ('move',s,'to',t)
    for i in range(1,5):
        print ('New Hanoi Example: hanoi(',i,',source, target, buffer)')
        print ('----------------------')

Open in new window

I tried to give values h1,2,3 but can not see these values in a debugger

this is so I can see moving parts
  • 2
2 Solutions
I don't really understand your question.

The code seems working and if you single step INTO the function you should be able to see n,s,t,b

What exactly does not work?

You could just set a breakpoint at line 3. and inspect n,s,b,t

or just insert following line after line 1 of your code. That's of course not using a debugger, but just adding traces, but sometimes this is faster and more efficient then singlestepping through code.
    print("%2d %10s %10s %10s" % (n, s,t,b))

Open in new window

The formatting in the print statement is just there to have the columns aligned
Walter RitzelSenior Software EngineerCommented:
According to your algorithm, h1, h2 and h3 will never have a value, because your hanoi function does not return a value.
Also, you are print the movement only when n=1, which seems odd. Double check your logic on this piece.
rgb192Author Commented:
print statement and

h1,2,3 never return a value.
The implementation is doing what it's supposed to do.

However as Walter stated. h1, h2, h3 will always be none.
and are not needed, so you could rewrite the code as

Open in new window

as the recursive calls without value assignments are sufficient

The whole idea of towers of Hanoi ( http://en.wikipedia.org/wiki/Tower_of_Hanoi ) is to move a disk only when n is 1.
the recursive calls and the fact that permutations are performed over s,t,b  are 'just' there to determine the order of the moves.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now