Spectrum is now read-only. Learn more about the decision in our official announcement.


Elements of AI is a two part online course about AI and this community is for the participants of the course to discuss. Please join our new community at


Exercise 2 Advanced - Wrong answer error?

July 14, 2021 at 6:43pm

Exercise 2 Advanced - Wrong answer error?

July 14, 2021 at 6:43pm
Hi there, I was doing Exercise 2 in the advanced mode. I am pretty sure the output is the right one ( PAN NYC CAS AMS HEL 283.7 kg ), but the test button keeps saying it is wrong. Can anyone confirm if the result is the correct one?

July 20, 2021 at 7:44am
The answer was correct, it was just that the code has to meet some specifications. I was calculating the smallest km distance in the recursion, then multiplying by the CO2 in the main. The multiplication by CO2 has to be done in the recursion also.

July 22, 2021 at 4:24pm
yes correct

July 26, 2021 at 8:11pm
Hi (raulf), that's right. We have added a comment to the template code highlighting this fact now. Hopefully it doesn't cause confusion anymore. Sorry for the inconvenience it caused you!
The error occurs as the testing system in the backend calls the main method multiple times, which results in incorrect values of the global variable over subsequent function calls. Also, it's generally a good coding practice to keep code self-contained to prevent unintended consequences - like this one ;)