On Fri, 1 Aug 2008 03:19:25 -0600, "Prasad, Mrunalini"
<> declaimed the following in
gmane.comp.python.general:
> Hello:
>
> I am getting the above error while tryign to run the tower of hanoi
> program. The error is at line 42 highligted in red below. PLease advise
>
Note 1: color coding does not get past pure text email/news clients.
> #!/usr/bin/env python
>
> class Hanoi:
>
> def __init__(self, N):
> self.N = N
>
> try:
> raise ValueError(N)
> except ValueError, e:
> print "bad! value: %d" % e.value
>
Indentation is incorrect here... The unindented try: has ended the
definition of class Hanoi; as a result, all the indented stuff below is
seen as part of the except: branch...
> def display():
>
> print "A"
> for i in range(N):
> print "%d\n", A[i]
> i += 1
What do you expect that i += 1 to be performing? It's just going to
be replaced by the next value in the range() iteration.
Also, print statements already include a newline so this would be
trying to double space the output...
Moreover, you are printing a literal "%d", a new-line, and the value
of some global variable named A (which doesn't exist!) on the next line.
You'd be better off just using:
for itm in A:
print itm
<snip>
> def move(source, dest):
>
> i = 0;j = 0
> while ((source + i) == 0) and (i < N):
What is source -- better be some sort of numeric data type...
This looks more like a badly translated C program which was using
pointer arithmetic to index through an array given the starting address.
> dest + j - 1 = source + i
Especially here... I suspect the C looked something like
*(dest + j -1) = *(source + i)
I suggest reading the Python tutorial first before trying to port a
program from another language.
--
Wulfraed Dennis Lee Bieber KD6MOG
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff:
web-)
HTTP://www.bestiaria.com/