Keep failing at the last assignment

It is about the first part of the assignment that I am having trouble with:

(assignment) jovyan@5103d145da83:~/work/assignment_part_1$ python unittests.py
Initial list: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
Indices to remove: {0, 2, 4, 5, 6, 8, 11, 13, 14, 15, 16, 18, 19, 20, 21, 22, 24, 27, 28}
List after removal: [2, 4, 8, 10, 11, 13, 18, 24, 26, 27, 30]
magic_list[0] after division: 2
magic_list[1] after division: 2
magic_list[2] after division: 1
magic_list[3] after division: 1
magic_list[4] after division: 1
magic_list[5] after division: 1
magic_list[6] after division: 1
magic_list[7] after division: 1
magic_list[8] after division: 1
magic_list[9] after division: 1
List after integer division: [2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 30]
Adding 2, current summation: 2
Adding 2, current summation: 4
Adding 1, current summation: 5
Adding 1, current summation: 6
Adding 1, current summation: 7
Adding 1, current summation: 8
Adding 1, current summation: 9
Adding 1, current summation: 10
Adding 1, current summation: 11
Adding 1, current summation: 12
Adding 30, current summation: 42
Magic summation is equal to: 42.
Failed test case: magic_summation executed properly, but output is incorrect for parameters n = 30 and seed = 10.
Expected: 50
Got: 42

I see no problem and the answer I believe should be 42. Is there something I am misunderstanding here?

Hi!

It looks like ChatGPT could not fully translate the code from Python 2 to Python 3. You may have to be a bit more specific, by asking it to list the major changes from Python 2 to Python 3. I can give you a hint, there was a major change regarding division. Maybe this is something you can ask ChatGPT ;-).

Best,
Lucas

1 Like

I doubt about it. Looking at the log files, I think it correctly applied the algorithm. You removed the indices, then for the remaining numbers, you apply divisions (applying floor function) and add them. I am now guessing that maybe the numpy seed numbers are generated differently due to a possible version mismatch or something like that.

@Taxxi Your List after removal: [2, 4, 8, 10, 11, 13, 18, 24, 26, 27, 30] doesn’t look right. I guess you’re using a sorted reverse list for removal to retain the indices.
Print out the list after removal in the py27 code and compare

This assignment is tricky, you have to careful craft your prompt with the llm, otherwise you will get stuck in trial and error copy and pasting code in an endless loop, if you keep going the llm could also tell you that the original py2 code that returns instead of 50 with input 30 and seed 10 should return 42 instead. Just focus on telling him that you stricktly have to convert from py2 to py3 without any change in logic and focusing on the division handling difference as stated by others. In my case he also handled numpy problems with random seeding, so maybe you could ask that too, there are differences between the versions.

7 Likes

@joyless Your comment was golden. The only that helped me. Thank you!

2 Likes

@Taxxi, you may attempt to try other LLMs as ChatGPT sometimes end-up looping within the same cycling answer. Start fresh, this exercise as mentioned above is a bit tricky and somehow a bit frustrating in the good sense. Good luck.

Thanks everyone. I had to create debugging codes for python2 version, and compare it with the debugging of python3 version, and then chatGPT finally understood what it did wrong.

This helps me. I also asked GPT to play the expert role, and provided feedbacks to it. It only took 2 rounds of conversation for that. But God knows how much time I spent before this solution hhh

some other information that might be useful for somebody: I used the gpt 4o offered by the course after trying official gpt, claude, cursor. Also, restart the new conversation when the previous ones failed

this is the exact prompt I used and I added another / beside the float division and it worked finally :sob:

This assignment was just updated, please refresh your assignment before you proceed.

I have been reading the suggestions. I eyeballed the code. I’m still having problems. I run the Python 2.7 code with n=30, seed=10 and I get 50. Using ChatGPT 4o, my converted code gets 50 as well. I run unittest.py and I get:

Failed test case: magic_summation executed properly, but output is incorrect for parameters n = 30 and seed = 10.
Expected: 46
Got: 50

I submitted and I get:
Failed test case: magic_summation executed properly, but output is incorrect for parameters n = 10 and seed = 79.
Expected:
18.16111111111111,
but got:
16.

Cheers,
Andrew

Don’t worry. I solved it. I used ChatGPT 4o. I find it all a bit strange.

Hi @andrewfr,

There as a bug introduced in a previous fix. Now it is fixed, please try resubmitting your assignment.