# Data scientist : Analytics path / EXAM DATA SCIENCE FOUNDATION 1

Hi,
I’m very new at coding, I’m working to be Data Analyst this year
I’m following the “Data Science : Analytics” path on Codecademy. In the coding exam, I’m struggling with this question :

The following dictionary contains the test scores of students in three different components of an exam:

test_scores = {“Gina”:[80, 72, 90], “Javed”:[88, 68, 81], “Siobhan”:[80, 82, 84], “Pedro”:[98, 96, 95], “Marcel”:[78, 80, 78], “Dilip”:[64, 60, 75]}
However, the teacher realizes that there was an error in one of the questions in the first component of the exam.

Modify test_scores to reflect this change by adding 1 point to the first component of each student’s exam. (Hint: use a for loop!)
Write it into a text file, modified_scores.txt.

My code was :

test_scores = {“Gina”:[80, 72, 90], “Javed”:[88, 68, 81], “Siobhan”:[80, 82, 84], “Pedro”:[98, 96, 95], “Marcel”:[78, 80, 78], “Dilip”:[64, 60, 75]}

print(test_scores)

## Modify dictionary

for student, scores in test_scores.items():
scores[0] += 1
print(test_scores)

## Write to a text file

with open(“modified_scores.txt”, “w”) as f:
for student, scores in test_scores.items():
f.write(f"{student}: {scores}\n")

But for the text file part, I’ve this error message :

{“passed”:false, “errorMessage”: “Did you write the modified scores to the modified_scores.txt ?”} {“passed”: false, “errorMessage”: “Expected new file modified_scores.txt to be created.”}

I’ve tried tons of responses but all ended with this error message.
Somebody can help me or explain to me ?

Thanks for you’re help !

Hi! From looking at your code, it seems like there are some formatting issues in the text file. It looks like the test is expecting the text file to contain each student’s name and modified scores on a separate line, with the scores separated by commas instead of spaces.

Here’s an example of how you can modify your code to produce the expected output:

``````test_scores = {"Gina":[80, 72, 90], "Javed":[88, 68, 81], "Siobhan":[80, 82, 84], "Pedro":[98, 96, 95], "Marcel":[78, 80, 78], "Dilip":[64, 60, 75]}

# Modify dictionary
for student, scores in test_scores.items():
scores[0] += 1

# Write to a text file
with open("modified_scores.txt", "w") as f:
for student, scores in test_scores.items():
# Join the scores with commas
score_str = ",".join(str(score) for score in scores)
# Write each line to the file with the correct format
f.write(f"{student}: {score_str}\n")
``````

This should produce a text file that looks like this:

``````
Gina: 81,72,90
Javed: 89,68,81
Siobhan: 81,82,84
Pedro: 99,96,95
Marcel: 79,80,78
Dilip: 65,60,75
``````

Hope this helps! Let me know if you have any further questions.

Hi! did you find the solution? I am having the same problem

1 Like

I tried like this however i am having the same problem

{“passed”: false, “errorMessage”: “Did you write the modified scores to the `modified_scores.txt` ?”} {“passed”: false, “errorMessage”: “Expected new file `modified_scores.txt` to be created.”}

1 Like

Hi zaida, did you ever find a solution to this problem? I am having the same issue.

I am also having the same issue.

me too
someone found a solution?

1 Like

The following code snippet worked for me

``````with open(“modified_scores.txt”, “w”) as f:
f.write(str(test_scores))
``````