-
Notifications
You must be signed in to change notification settings - Fork 0
Completed the about_scoring_project koan #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devel
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of comments! I went deep into some Python-specific concepts. Please address my code comments to see if my explanations made sense to you.
repeated_nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | ||
for number in dice: | ||
repeated_nums[number]=repeated_nums[number] + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dice have 6 possible values, but the repeated_nums
variable in your solution has 10 total values. Was this done because you were getting list index out of range
errors when the array had only 6 values, and increasing the size fixed it? If that is the case, then let me explain why.
Sequences (list
, tuple
, set
, string
, etc.) in Python and most programming languages are zero-based. This means that the elements are numbered starting at 0. The first element has index 0, the second element has index 1, and so on. When you create repeated_nums
with 6 elements, you get the following:
# Index 0 1 2 3 4 5
# Die Value 1 2 3 4 5 6
# repeated_nums [0, 0, 0, 0, 0, 0]
The out of index errors were happening because you were iterating over the values of the dice,
for number in dice:
which set number
to some value between 1 and 6, but were using this value as an index.
repeated_nums[number] [...]
The problem here is that values go from 1 to 6, but indexes go from 0 to 5. This means that whenever the value of number
is 6, you will get an list index out of range
error, because the list does not have an index 6; its maximum index is 5.
A quick solution to this is to substract 1 from the value of the dice, so that both the indexes and dice values are in the same range.
repeated_nums = [0, 0, 0, 0, 0, 0]
for number in dice:
repeated_nums[number-1] = repeated_nums[number] + 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't even notice this error because for some reason I forgot that the dice goes only to 6
(I did not forget that it can't be 0
tho haha)
So what I was trying to do is to compare the values to the numbers from 1
to 9
, when trying to make the list shorter I run with that error, so that fixes it!
All comments addressed! |
Completed and ready for review!