joelgrus / data-science-from-scratch

code for Data Science From Scratch book
MIT License
8.63k stars 4.5k forks source link

The number calculating mistakes in introduction.py #4

Open iphyer opened 9 years ago

iphyer commented 9 years ago

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.

iphyer commented 9 years ago

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.

daniel-rhoades commented 5 years ago

+1