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

Posted on 2014-08-06
Last Modified: 2014-08-07
    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
Question by:rgb192
    LVL 16

    Accepted Solution

    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
    LVL 15

    Assisted Solution

    by:Walter Ritzel
    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.

    Author Closing Comment

    print statement and

    h1,2,3 never return a value.
    LVL 16

    Expert Comment

    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 ( ) 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

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
    Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" " You can also get information on Python scripting language from the above mentioned we…
    Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
    Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now