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 :
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.
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.
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.
Im writing the code in python and got a similiar issue with case 3 and case 4 like previously mentioned.
But i cant seem to figure out why my Thor runs out of bounds.
I declared the variables outside of the loop and initiated them with 0
After getting the inputs i overwritten them with the inital_tx / ty values.
Additionaly i Checked for the conditions of my if statements. Which i cant seem to find the issue.
I get the exact error Thibaud discribes cause he wants to go another SW
and runs to position (-1,5)
Hi. I’ve resumed learning programming after so long.
Can anyone tell me why this code does not even start?
import java.util.*;
import java.io.*;
import java.math.*;
class Player {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int lightX = in.nextInt(); // the X position of the light of power
int lightY = in.nextInt(); // the Y position of the light of power
int initialTx = in.nextInt(); // Thor's starting X position
int initialTy = in.nextInt(); // Thor's starting Y position
// game loop
while (true) {
int remainingTurns = in.nextInt(); // The remaining amount of turns Thor can move. Do not remove this line.
//I've tried to express "go east until the X position of Thor and Power source become the same."
Integer.valueOf(lightX);
Integer.valueOf(initialTx);
while (lightX = initialTx) {
System.out.println("E");
}
}
}
}
In a game such as “Power of Thor”, there are 2 actors: the simulation and your program. They interact together only through their IO (input/output), nothing else. The simulation knows nothing of your program.
When you write int lightX = in.nextInt(), you wait for and read an input line as an int to store it into a variable named lightX. Your variable is just a box with a value inside. Its value won’t change magically to reflect an updated Thor’s position.
So, when you later write :
while (lightX = initialTx) {
System.out.println("E");
}
There is absolutely no way for lightX and intialTx to change. It is always false or true. In the first case you output nothing, in the second, you output an infinite sequence of 'E'. None of these behaviors is correct.
Also, calling the Integer.valueOf method does nothing (it converts an unboxed value into a boxed one, but since you ignore the returned value, it doesn’t even matter). Even if calling this method was doing something useful, it wouldn’t change anything since the call is done outside the inner while loop.
Lastly, you can’ translate “until the X position of Thor and Power source become the same” by “while lightX equals initialTx”, it is just wrong.
Thanks for your advice.
In short, my mistakes might be:
-the truth or falsehood of while loop can’t be changed
-the way of and place to write Integer.valueOf are pointless
-initialTx is starting X position of Thor, not where currently he is
The way you put it is quite confusing. Let’s be clearer:
Obviously, the condition of while loops, in general, can change. They would be mostly useless otherwise. It’s simply that, in your code, you doesn’t update anything in order to change it.
Your usage of Integer.valueOf is obviously pointless. What do you hope to achieve by using it?
Your intiatTx is initialized with Thor’s starting position and you do not change it, so it stays this way. If you were trying to update it in your loop, it could be the updated Thor’s position. Once again, its your choice. By the way, your inner loop is completely unnecessary.
It’s hard to put yourself in someone else’s mind, but it seems like you are not programming, but simply stating facts (or rules) for Thor to follow. That’s not how it works. You can’t code abstract things such as “this is Thor position, whatever it is” or “go east until Thor and the light share the same x coordinate”. These kind of sentences describe your goal, not how to actually do it (in other words, it’s a specification, not an implementation).
If it could help you, here’s how your goal of “going east until Thor and the light share the same x coordinate” could be implemented:
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
final int lightX = in.nextInt(); // the X position of the light of power
final int lightY = in.nextInt(); // the Y position of the light of power
final int initialTx = in.nextInt(); // Thor's starting X position
final int initialTy = in.nextInt(); // Thor's starting Y position
int thorX = initialTx;
// game loop
while (lightX != thorX) {
// In this specific contest, the turn's input is not useful and you don't neet to read it.
final int remainingTurns = in.nextInt();
System.out.println("E");
thorX = thorX + 1;
System.err.println("Before looping: thorX == " + thorX);
System.err.println("Before looping: (lightX != thorX) == " + (lightX != thorX));
}
}
Hello
Can anybody help me pls with this 75%-Case? I really dont understand what is wrong with my code
“The validators differ from the puzzle test cases to prevent hard coded solutions. This is why you can have some fails here even if all of the tests provided in the IDE have been successfully passed.”
Hi all!
I got problem while running this game in Haskell:
This is my code, it should work just fine, and I test it on my VScode it runs on demand
But it runs different in Game.
Anyway this is my code :
putStrLn (determ initialtx lightx initialty lighty)
determ :: Int -> Int -> Int -> Int -> String
determ a b c d
| x > 0 && y > 0 = "SE"
| x > 0 && y < 0 = "NE"
| x < 0 && y > 0 = "SW"
| x < 0 && y < 0 = "NW"
| x == 0 && y < 0 = "N"
| x == 0 && y > 0 = "S"
| x > 0 && y == 0 = "E"
| x < 0 && y == 0 = "W"
where
x = b - a
y = d - c