Hi @M4a,
There is an issue with GPT 4o for C2 (it is pointing to 3.5), we are working on it with Coursera and we soon will have it fixed.
Hi @M4a,
There is an issue with GPT 4o for C2 (it is pointing to 3.5), we are working on it with Coursera and we soon will have it fixed.
This was an interesting assignment and took a bit of time for me.
But solved it.
moving to Course 3.
Unfortunately i am still having trouble with Assignment 1 (Assignment 2 was indeed easy):
Now my code works, but as some others, i get different sums.
It seems the LLM’s swing around these topics without finding any working solution:
To ensure consistent results across Python versions, let’s make sure:
So, any hints where the problem might be?
A couple of suggestions:
There is an issue with the part_1 assignment script itself. Original script for Python 2.7 is using set() function to generate indices_to_remove and then iterates over that set, without applying any sorting to it.
Here is what LLM has to say about iteration order in sets in 2.7 and 3.6:
So there is basically no way to guarantee that the iteration order over indices_to_remove will be the same in both versions, unless you can change the 2.7 version, which is prohibited in this assignment.
The fact that the scripts might (and do) behave the same way and produce the same result for n = 30, seed = 10 arguments and pass unit tests attached to this assignment is purely coincidental. You can try the passing solution with the arguments n = 10, seed = 3 and see what happens.
Bernard Leong was right.
For part 1
You must use the ChatGPT provided by the course, which is running ChatGPT 3.5, and then the answer is correct.
I don’t see the science behind it, but it works.
I wasted all the afternoon until I found Leong’s advice.
For Part 2
I used Chat GPT o1-mini, because the ChatGPT provided by the course was not accurate and I got the right solution working with Chat GPT o1-mini
The python27 code has bugs in indice generation and removal logic. For the test case, I get 42.
chatGPT explains:
That is correct.
The assignment, however, asks for the following:
“Your objective is to update the function for compatibility with Python 3, maintaining its current functionality as it operates in Python 2.”
As I read it, “maintaining its current functionality” implies getting the same result for any pair of input parameters in both Python 2 and Python 3 versions, and that’s where you’re running into an issue of different set implementations in different versions.
Though it’s noted as fixed earlier in this thread, when I submit the assignment, part 2 returns:
Visit the Discussion forum to see if your peers are experiencing or have found resolutions for similar errors. If the error isn’t resolved in 24 hours, please reach out to Coursera through our Help Center.
My submission.tar.gz contains df_convert.py, gen_employee_schedule.py, internal_stats.py, and requirements.txt that works in the terminal. Not sure what it’s complaining about.
print
statements to use the Python 3 syntax with parentheses.it.next()
with next(it)
to use the Python 3 iterator protocol.indices_to_remove
start from 1
, matching the original code.//
for integer division to mimic Python 2’s behavior in Python 3.n = 3
and seed = 23
:Step-by-Step Execution:
python
Copy code
numpy.random.seed(23)
num_indices_to_remove
:python
Copy code
num_indices_to_remove = int(numpy.random.random() * n) + 1
# First random number: ~0.517
# num_indices_to_remove = int(0.517 * 3) + 1 = 1 + 1 = 2
indices_to_remove
:python
Copy code
indices_to_remove = set(int(numpy.random.random() * n) + 1 for _ in range(num_indices_to_remove))
# Next random numbers: ~0.947, ~0.765
# Indices: int(0.947 * 3) + 1 = 2 + 1 = 3
# int(0.765 * 3) + 1 = 2 + 1 = 3
# indices_to_remove = {3}
magic_list
:python
Copy code
magic_list = [1, 2, 3]
magic_list[idx]
for idx
in indices_to_remove
.idx
ranges from 1
to n
, and list indices start at 0
, when idx = 3
, we check if 3 < len(magic_list)
, which is False
for a list of length 3
.python
Copy code
# i = 0
magic_list[0] = magic_list[1] // magic_list[0] = 2 // 1 = 2
# i = 1
magic_list[1] = magic_list[2] // magic_list[1] = 3 // 2 = 1
# magic_list = [2, 1, 3]
python
Copy code
magic_summation_value = 2 + 1 + 3 = 6
plaintext
Copy code
Magic summation is equal to: 6.
indices_to_remove
did not match those in the original code due to differences in how random indices were generated and how elements were deleted from the list.magic_list
:
magic_summation.py
.bash
Copy code
python magic_summation.py 3 23
plaintext
Copy code
Magic summation is equal to: 6.
Feel free to test the script with different values of n
and seed
to ensure it behaves as expected.
Example:
bash
Copy code
python magic_summation.py 5 42
Expected Output:
plaintext
Copy code
Magic summation is equal to: 7.
To resolve this, we need to:
RandomState
: Switched back to numpy.random.RandomState(seed)
to use the legacy random number generator (MT19937
), ensuring consistent random numbers across different NumPy versions.indices_to_remove
are from 1
to n
inclusive, matching the original code.magic_list
, we use the indices as-is, without adjusting for zero-based indexing. This replicates the original code’s off-by-one error.if idx < len(magic_list)
ensures we don’t attempt to delete an index that’s out of range.Thank you aitarmak! this is helpful! At end of the day, we still need print to help us debug and solve the issue instead of GPT
I used ChatGPT o1-preview to solve the assignment_part_1. The suggested changes by [Olu_Idiakhoa] mentioned here did the trick. Thanks!
I am stuck on exactly same thing; anyone could get past this issue?
any post helping to solve it? I failed to solve it myself so far (with different LLMs) and did not see any post that hints to solution of this issue.
Hey all,
I’ve updated the assignment to remove the set function, and performing a “manual” deduplication of the list.
I have also improved the unittests as well as fixed one value that was wrong (the last expected value as 50 but actually it should be 46).
You all may refresh your workspace to get a new copy it it.
I would also suggest you all to explicitly tell an LLM to only make the necessary changes in the code to run it in Pyhon 3. If you let it, it will perform several changes and it will increase the likelihood of changing the final value.
@Lucas, can we put the “refresh your workspace” instructions here on the course forum? Maybe in a Resources “FAQ” for this course?
Currently they’re sort of hidden away on Coursera.
@lucas.coutinho @TMosh
I think there is some issue with the grader with Assignment 1. It still says Failed Test, but the result is the same for me when I run the python27 and python 3 versions. The result from the grader is a float value, that looks incorrect.
I have refreshed the workspace and fetched the latest updated version of the code.
For now, I have edited my code to do a division(/) instead of integer division (//). This passes through the grader.
Thanks for catching this. It is fixed now.
Hello I’m still having issues on the grading, where i get the same result using both the python3 and the python2 functions but the grader expects something else.
At the moment I get this from the grader:
Failed test case: magic_summation executed properly, but output is incorrect for parameters n = 19 and seed = 27.
Expected:
33,
but got:
29.
but both functions give me the same answer:
(assignment) jovyan@12933eed2428:~/work/assignment_part_1$ conda activate python27
(python27) jovyan@12933eed2428:~/work/assignment_part_1$ python magic_summation_python27.py
Magic summation is equal to: 29.
(python27) jovyan@12933eed2428:~/work/assignment_part_1$ conda activate assignment
(assignment) jovyan@12933eed2428:~/work/assignment_part_1$ python magic_summation.py
Magic summation is equal to: 29.