Power Of Thor - Episode 1 - Puzzle discussion

Hi guys!

I don’t understand why if I remove the System.err my code doesn’t work

// game loop
    while (true) {
        int remainingTurns = in.nextInt(); // The remaining amount of turns Thor can move. Do not remove this line.
        
        if (initialTx > lightX && initialTy == lightY) {
            System.out.println("W");
        } else if (initialTx < lightX && initialTy == lightY) {
            System.out.println("E");
        }
        
        if (initialTy > lightY && initialTx == lightX) {
            System.out.println("N");
        } else if (initialTy < lightY && initialTx == lightX) {
            System.out.println("S");
        }
        
        
        if (initialTx < lightX && initialTy < lightY) {
                System.err.println("Thor position is X: " + (initialTx++) + ", Y: " + (initialTy++));
                System.out.println("SE");
        } else if (initialTx < lightX && initialTy > lightY) {
                System.err.println("Thor position is X: " + (initialTx++) + ", Y: " + (initialTy--));
                System.out.println("NE");
        } else if (initialTx > lightX && initialTy < lightY) {
                System.err.println("Thor position is X: " + (initialTx--) + ", Y: " + (initialTy++));
                System.out.println("SW");
        } else if (initialTx > lightX && initialTy > lightY) {
                System.err.println("Thor position is X: " + (initialTx--) + ", Y: " + (initialTy--));
                System.out.println("NW");
        }
    }

If you remove your debug printing, your position variables are no more updated.

1 Like

Hello everybody,
I’ve just starting in programming. For this exercise, i’ve looked in the clues, and the solutions it gives doesn’t pass every test when I try it; So I tried to create a another solution, but based on the first one.here it is :
if thor_x > light_x :

    direction_thor = "W"

    thor_x -= 1

elif thor_x < light_x :

    direction_thor = "E"

    thor_x += 1

    

if thor_y > light_y :

    direction_thor = "N"

    thor_y -= 1

elif thor_y < light_y :

    direction_thor = "S"

    thor_y += 1



if thor_x > light_x, and thor_y > light_y :

    direction_thor = "NW"

    thor_x,thor_y -= 1

elif thor_x > light_x, and thor_y < light_y :

    direction_thor = "SW"

    thor_x -= 1, and thor_y += 1

if thor_y > light_y,and thor_x < light_x :

    direction_thor = "NE"

    thor_x += 1, and thor_y -= 1

elif thor_y < light_y, and thor_x < light_x : 

    direction_thor = "SE"

    thor_x, thor_y += 1

From the moment I write if thor_x > light_x, and thor_y > light_y : , the console tells me that it is not a function. I use python, can you help me, and tell me why it doesn’t work ?
Thanks for having read this message

I guess it’s logical that you make the exact same mistake in English and Python.

:woman_teacher: So, here is the rule: there is seldom if ever a comma before the “and” conjunction in English (as well as in French by the way and probably many other languages) and never in Python (or any other programming language which uses the “and” keyword).

Next time, we will have a look on punctuation rules regarding spacing and uppercase. Unfortunately, a topic nobody cares about when coding.

1 Like

Thanks a lot

Yeah, there’s still a bug. Drove me nuts, but at least it helped me solidify some basic syntax in my mind. I ended up having to compare my code to the solution code. Basically, every bit of the code was identical, except the variable names. It kept showing expected “;” on the same line, but nothing would change the error code, even adding a “;” in random places. Only worked with a solution copy & paste.

Console output doesn’t display where the error is

What do you mean?
This is the error you have on test 3: