data-science-from-scratch
data-science-from-scratch copied to clipboard
The number calculating mistakes in introduction.py
The number calculating mistakes in introduction.py
The length of the users list is 11 not 10 so the answer of average user's friends is 2.182 instead of 2.4.
num_users = len(users) # 11
avg_connections = total_connections / num_users # 2.1818181818181817
I have changed it AND add a new comment on the line to calculate the length of users.
I mistake you code the really problem is in the code of users.
users = [
{ "id": 0, "name": "Hero" },
{ "id": 1, "name": "Dunn" },
{ "id": 2, "name": "Sue" },
{ "id": 3, "name": "Chi" },
{ "id": 4, "name": "Thor" },
{ "id": 5, "name": "Clive" },
{ "id": 6, "name": "Hicks" },
{ "id": 7, "name": "Devin" },
{ "id": 8, "name": "Kate" },
{ "id": 9, "name": "Klein" },
{ "id": 10, "name": "Jen" }
]
The last entry { "id": 10, "name": "Jen" } should be removed.
+1