4 ms·
I think you forgot to put quotes around "Girl" on line 46. Edit: Actually I'm not sure what the problem is but I'm getting 0 girls and a divide-by-0 error. Edi
by sp332 10y ago
I think you forgot to put quotes around "Girl" on line 46. Edit: Actually I'm not sure what the problem is but I'm getting 0 girls and a divide-by-0 error.
Edit2: I don't remember why I was getting all girls, but the other issue was integer division. If boybrothers/boys truncates to 0, then (girlbrothers/girls)/(boybrothers/boys) will divide by 0.
- mudbungie 10y agoActually, line 46 is referencing the class Girl, so you wouldn't want quotes. Technically, you're supposed to use try/except duck-typing in Python, but I often find that clearer code comes out of assertions where you literally check the type of an object instead of handling errors. This was no exception. (Sorry, bad pun) You might try throwing in a random seed. I just trusted that my system would iterate enough that it wouldn't matter, but if you're getting all boys (I'm not sure that's the case, but you said that you're getting 0 girls...), it could be that for whatever reason, the system might not be advancing the seed. Try inserting the following two lines immediately after import random: from datetime import datetime random.seed(datetime.now())
- kqr 10y agoRun it in Python 3.
- sp332 10y agoYeah in hindsight that was pretty obvious. I guess the real bug was leaving off the #! line :)